https://git.reactos.org/?p=reactos.git;a=commitdiff;h=6eb8fe4f82782cce064ea3dd51dfe6dec9a57b81

commit 6eb8fe4f82782cce064ea3dd51dfe6dec9a57b81
Author:     Adam Słaboń <[email protected]>
AuthorDate: Wed Apr 19 23:12:11 2023 +0200
Commit:     GitHub <[email protected]>
CommitDate: Wed Apr 19 23:12:11 2023 +0200

    [NTOS:MM] MmCanFileBeTruncated: Check whether second (optional) parameter 
was passed (#5248)
    
    
    Second parameter is optional, so mark it as such and check whether it was 
passed. Fixes a sporadic 0x24 bugcheck caused by access violation when running 
ReactOS on NTFS volume with WinXP ntfs.sys.
---
 ntoskrnl/mm/section.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/ntoskrnl/mm/section.c b/ntoskrnl/mm/section.c
index 9323a6da196..49c0e0e8f4f 100644
--- a/ntoskrnl/mm/section.c
+++ b/ntoskrnl/mm/section.c
@@ -4209,9 +4209,11 @@ MmMapViewOfSection(IN PVOID SectionObject,
 /*
  * @unimplemented
  */
-BOOLEAN NTAPI
-MmCanFileBeTruncated (IN PSECTION_OBJECT_POINTERS SectionObjectPointer,
-                      IN PLARGE_INTEGER   NewFileSize)
+BOOLEAN
+NTAPI
+MmCanFileBeTruncated(
+    _In_ PSECTION_OBJECT_POINTERS SectionObjectPointer,
+    _In_opt_ PLARGE_INTEGER NewFileSize)
 {
     BOOLEAN Ret;
     PMM_SECTION_SEGMENT Segment;
@@ -4237,7 +4239,7 @@ MmCanFileBeTruncated (IN PSECTION_OBJECT_POINTERS 
SectionObjectPointer,
         /* If the cache is the only one holding a reference to the segment, 
then it's fine to resize */
         Ret = TRUE;
     }
-    else
+    else if (NewFileSize != NULL)
     {
         /* We can't shrink, but we can extend */
         Ret = NewFileSize->QuadPart >= Segment->RawLength.QuadPart;
@@ -4248,6 +4250,12 @@ MmCanFileBeTruncated (IN PSECTION_OBJECT_POINTERS 
SectionObjectPointer,
         }
 #endif
     }
+    else
+    {
+        DPRINT1("ERROR: File can't be truncated because it has references held 
to its data section\n");
+        Ret = FALSE;
+    }
+
     MmUnlockSectionSegment(Segment);
     MmDereferenceSegment(Segment);
 

Reply via email to