Bounds-check BufferView::read - #352
Merged
asmaloney merged 1 commit intoAug 12, 2026
Merged
Conversation
Passing a short (< 1024 byte) memory buffer to CheckedFile causes an out-of-bounds read and ASAN failure. CheckedFile::readPhysicalPage always requests a full physicalPageSize regardless of how many bytes remain, and BufferView::read copied that many bytes without comparing against streamSize_. The file-backed branch already refuses a short read; this makes the buffer-backed branch behave the same way. The check is written as ( count > streamSize_ - start ) rather than ( start + count > streamSize_ ) so it cannot itself overflow.
Owner
|
Thanks for this (and our conversation). I have a test written up already (based on yours) since I implemented the other file length fix I mentioned. I will push that separately. (I also fixed the failing tests when the test files aren't present.) I'll also handle the change log later (I tend to do that in batches). |
asmaloney
added a commit
that referenced
this pull request
Aug 12, 2026
Fixed by #352 Co-authored-by: spartan <39662153+spartan8806@users.noreply.github.com>
7 tasks
asmaloney
added a commit
that referenced
this pull request
Aug 12, 2026
) Fixed by #352 Co-authored-by: spartan <39662153+spartan8806@users.noreply.github.com>
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.
Passing a short (< 1024 byte) memory buffer to
CheckedFilecauses an out-of-bounds read and ASAN failure.CheckedFile::readPhysicalPage()always requests a fullphysicalPageSizeregardless of how many bytes actually remain, andBufferView::read()copied that many bytes without comparing againststreamSize_. The file-backed branch immediately below it already refuses a short read — this makes the buffer-backed branch behave the same way.The check is written as
count > streamSize_ - startrather thanstart + count > streamSize_so it can't itself overflow.Verified against a clean checkout of
master:heap-buffer-overflow,READ of size 1, atCheckedFile.cpp:177E57Exceptionunder bothChecksumAllandChecksumNone, exit 0, no ASAN reportHappy to add a CHANGELOG entry under 3.4.0 → Fixed once this has a PR number, and a regression test that feeds a short buffer to the memory constructor — just say the word and I'll push either to this branch.