[NTOS:MM] Fix regression of MmCanFileBeTruncated

This commit is contained in:
Jérôme Gardou 2021-02-01 18:20:18 +01:00
parent 7f7abc9838
commit c0bf352069

View file

@ -4115,7 +4115,7 @@ MmCanFileBeTruncated (IN PSECTION_OBJECT_POINTERS SectionObjectPointer,
} }
MmLockSectionSegment(Segment); MmLockSectionSegment(Segment);
if ((Segment->SectionCount == 1) && (SectionObjectPointer->SharedCacheMap != NULL)) if ((Segment->SectionCount == 0) || ((Segment->SectionCount == 1) && (SectionObjectPointer->SharedCacheMap != NULL)))
{ {
/* If the cache is the only one holding a reference to the segment, then it's fine to resize */ /* If the cache is the only one holding a reference to the segment, then it's fine to resize */
Ret = TRUE; Ret = TRUE;
@ -4124,6 +4124,12 @@ MmCanFileBeTruncated (IN PSECTION_OBJECT_POINTERS SectionObjectPointer,
{ {
/* We can't shrink, but we can extend */ /* We can't shrink, but we can extend */
Ret = NewFileSize->QuadPart >= Segment->RawLength.QuadPart; Ret = NewFileSize->QuadPart >= Segment->RawLength.QuadPart;
#if DBG
if (!Ret)
{
DPRINT1("Cannot truncate data: New Size %I64d, Segment Size %I64d\n", NewFileSize->QuadPart, Segment->RawLength.QuadPart);
}
#endif
} }
MmUnlockSectionSegment(Segment); MmUnlockSectionSegment(Segment);
MmDereferenceSegment(Segment); MmDereferenceSegment(Segment);