[NTOSKRNL] When mapping data in CcMapData(), don't truncate offset to ULONG.
authorPierre Schweitzer <pierre@reactos.org>
Sat, 13 Jan 2018 20:27:29 +0000 (21:27 +0100)
committerPierre Schweitzer <pierre@reactos.org>
Sat, 13 Jan 2018 20:30:37 +0000 (21:30 +0100)
This would affect reads/writes on large volumes where offset is higher than what a ULONG can hold.

This really nasty bug was hitting CcMapData() but also CcPinRead() (due to the nature of its implementation)
and both were returning garbage data under certain circumstances with Ext2Fsd.

This should (I hope!) help some other FSDs to work better in ROS.

CORE-12456

ntoskrnl/cc/pin.c

index 6a0d675..0241927 100644 (file)
@@ -33,19 +33,19 @@ CcMapData (
     OUT PVOID *pBcb,
     OUT PVOID *pBuffer)
 {
-    ULONG ReadOffset;
+    LONGLONG ReadOffset;
     BOOLEAN Valid;
     PROS_SHARED_CACHE_MAP SharedCacheMap;
     PROS_VACB Vacb;
     NTSTATUS Status;
     PINTERNAL_BCB iBcb;
-    ULONG ROffset;
+    LONGLONG ROffset;
 
     DPRINT("CcMapData(FileObject 0x%p, FileOffset %I64x, Length %lu, Flags 0x%lx,"
            " pBcb 0x%p, pBuffer 0x%p)\n", FileObject, FileOffset->QuadPart,
            Length, Flags, pBcb, pBuffer);
 
-    ReadOffset = (ULONG)FileOffset->QuadPart;
+    ReadOffset = FileOffset->QuadPart;
 
     ASSERT(FileObject);
     ASSERT(FileObject->SectionObjectPointer);
@@ -101,7 +101,7 @@ CcMapData (
         }
     }
 
-    *pBuffer = (PVOID)((ULONG_PTR)(*pBuffer) + ReadOffset % VACB_MAPPING_GRANULARITY);
+    *pBuffer = (PUCHAR)*pBuffer + ReadOffset % VACB_MAPPING_GRANULARITY;
     iBcb = ExAllocateFromNPagedLookasideList(&iBcbLookasideList);
     if (iBcb == NULL)
     {