Skip to content

[BUGFIX] AbstractByteBuffer::getContentAt: catch the wrap of offset + size - #35

Merged
hasherezade merged 1 commit into
hasherezade:masterfrom
mkilijanek:fix/getcontentat-wrap
Nov 3, 2026
Merged

hasherezade merged 1 commit into
hasherezade:masterfrom
mkilijanek:fix/getcontentat-wrap

Conversation

@mkilijanek

Copy link
Copy Markdown
Contributor

getContentAt checked the requested area as offset + size > fileSize. With a size close to 2^64 the sum wraps to a small value, the check passes, and a pointer is returned for an area that is almost entirely outside the buffer. Such sizes come from unsigned underflows of PE-supplied fields (for example a value computed as dwLength - 10).

Change

Compare the size with what is left after the offset: size > fileSize - offset (offset < fileSize is already checked just above). One line.

Verification

A 0x100-byte ByteBuffer, built with -fsanitize=address,undefined:

call master this change
getContentAt(0x10, -8) non-NULL NULL
getContentAt(0x10, 0xf0) non-NULL non-NULL
getContentAt(0x10, 0xf1) NULL NULL

test.sh against bearparser_tests: 26 cases print OK with and without the change. x86/kernel32 : explist prints "Failed" on unmodified master too. In the sanitizer build the test run shows the same 11 reports (6 distinct places) before and after; this change adds none.

I did not look for every caller that can pass such a size.

… size

getContentAt checked the requested area as `offset + size > fileSize`. With a
size close to 2^64 the sum wraps to a small value, the check passes, and a
pointer is returned for an area that is almost entirely outside the buffer.
Such sizes come from unsigned underflows of PE-supplied fields, for example a
value computed as `dwLength - 10`.

Compare the size with what is left after the offset instead
(size > fileSize - offset; offset < fileSize is already checked above).

On a 0x100-byte ByteBuffer: getContentAt(0x10, -8) returned a non-NULL pointer
before and returns NULL now; getContentAt(0x10, 0xf0) is still accepted and
(0x10, 0xf1) is still rejected.
@hasherezade
hasherezade merged commit 3feb30b into hasherezade:master Nov 3, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants