Repository navigation
[BUGFIX] AbstractByteBuffer::getContentAt: catch the wrap of offset + size - #35
Merged
Merged
Conversation
… 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
getContentAtchecked the requested area asoffset + 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 asdwLength - 10).Change
Compare the size with what is left after the offset:
size > fileSize - offset(offset < fileSizeis already checked just above). One line.Verification
A 0x100-byte
ByteBuffer, built with-fsanitize=address,undefined:mastergetContentAt(0x10, -8)getContentAt(0x10, 0xf0)getContentAt(0x10, 0xf1)test.shagainstbearparser_tests: 26 cases print OK with and without the change.x86/kernel32 : explistprints "Failed" on unmodifiedmastertoo. 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.