Menu

#57 BitpackIntegerDecoder inputProcessAligned illegal memory access

open
nobody
None
1
2025-08-07
2025-08-07
Lee Bull
No

The method BitpackIntegerDecoder<registert>::inputProcessAligned() accesses memory off the end of the input buffer if the last record being processed is contained within the last word.</registert>

This occurs in the the line:
high = inp[wordPosition+1];

Suggested fix:

     // If the value is contained within the word
    if (bitOffset + bitsPerRecord_ <= 8 * sizeof(RegisterT))
        {
        // Take the value from the current word. Logical shift the low LSBit to bit 0
        w = low >> bitOffset;
        }
        else
        {
        // Access the high word to get additional bits for the record
        high = inp[wordPosition + 1];

        // swab if necessary
        SWAB(&high);

        /// Shift high to just above the lower bits, shift low LSBit to bit0, OR together.
        /// Note shifts are logical (not arithmetic) because using unsigned variables.
        w = (high << (8 * sizeof(RegisterT) - bitOffset)) | (low >> bitOffset);
        }

Discussion


Log in to post a comment.

MongoDB Logo MongoDB