diff --git a/reactos/lib/rtl/bitmap.c b/reactos/lib/rtl/bitmap.c index 6ceddf927ee..350e182191c 100644 --- a/reactos/lib/rtl/bitmap.c +++ b/reactos/lib/rtl/bitmap.c @@ -101,6 +101,11 @@ RtlpGetLengthOfRunClear( BITMAP_INDEX Value, BitPos, Length; PBITMAP_BUFFER Buffer, MaxBuffer; + /* If we are already at the end, the length of the run is zero */ + ASSERT(StartingIndex <= BitMapHeader->SizeOfBitMap); + if (StartingIndex >= BitMapHeader->SizeOfBitMap) + return 0; + /* Calculate positions */ Buffer = BitMapHeader->Buffer + StartingIndex / _BITCOUNT; BitPos = StartingIndex & (_BITCOUNT - 1); @@ -150,6 +155,11 @@ RtlpGetLengthOfRunSet( BITMAP_INDEX InvValue, BitPos, Length; PBITMAP_BUFFER Buffer, MaxBuffer; + /* If we are already at the end, the length of the run is zero */ + ASSERT(StartingIndex <= BitMapHeader->SizeOfBitMap); + if (StartingIndex >= BitMapHeader->SizeOfBitMap) + return 0; + /* Calculate positions */ Buffer = BitMapHeader->Buffer + StartingIndex / _BITCOUNT; BitPos = StartingIndex & (_BITCOUNT - 1);