Bug 1586070 - Read does not advance file position for files larger than 4GB on Win32. (See also bug 70765.) r=kaie
authorzbordas@kollective.com
Fri, 08 Nov 2019 09:31:16 +0100
changeset 4850 e31429fc131228989331dad7c7b583fce1e9ad0c
parent 4849 d03855113364d4a9f182a9f820b1787fd1100364
child 4851 50c1448672f16e98895a256575bdc0a382d1c0a5
push id348
push userkaie@kuix.de
push dateFri, 08 Nov 2019 08:31:32 +0000
reviewerskaie
bugs1586070, 70765
Bug 1586070 - Read does not advance file position for files larger than 4GB on Win32. (See also bug 70765.) r=kaie
pr/src/md/windows/ntio.c
--- a/pr/src/md/windows/ntio.c
+++ b/pr/src/md/windows/ntio.c
@@ -2247,16 +2247,17 @@ PROsfd
 PRInt32
 _PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 len)
 {
     PROsfd f = fd->secret->md.osfd;
     PRUint32 bytes;
     int rv, err;
     LONG hiOffset = 0;
     LONG loOffset;
+    LARGE_INTEGER offset; /* use for a normalized add of len to offset */
 
     if (!fd->secret->md.sync_file_io) {
         PRThread *me = _PR_MD_CURRENT_THREAD();
 
         if (me->io_suspended) {
             PR_SetError(PR_INVALID_STATE_ERROR, 0);
             return -1;
         }
@@ -2363,17 +2364,24 @@ PRInt32
             if (me->md.blocked_io_status == 0) {
                 if (me->md.blocked_io_error == ERROR_HANDLE_EOF) {
                     return 0;
                 }
                 _PR_MD_MAP_READ_ERROR(me->md.blocked_io_error);
                 return -1;
             }
 
-            SetFilePointer((HANDLE)f, me->md.blocked_io_bytes, 0, FILE_CURRENT);
+            /* Apply the workaround from bug 70765 (see _PR_MD_WRITE)
+             * to the reading code, too. */
+
+            offset.LowPart = me->md.overlapped.overlapped.Offset;
+            offset.HighPart = me->md.overlapped.overlapped.OffsetHigh;
+            offset.QuadPart += me->md.blocked_io_bytes;
+
+            SetFilePointer((HANDLE)f, offset.LowPart, &offset.HighPart, FILE_BEGIN);
 
             PR_ASSERT(me->io_pending == PR_FALSE);
 
             return me->md.blocked_io_bytes;
         }
     } else {
 
         rv = ReadFile((HANDLE)f,