Skip to content

Bounds-check BufferView::read - #352

Merged
asmaloney merged 1 commit into
asmaloney:masterfrom
spartan8806:fix/bufferview-read-bounds
Aug 12, 2026
Merged

Bounds-check BufferView::read#352
asmaloney merged 1 commit into
asmaloney:masterfrom
spartan8806:fix/bufferview-read-bounds

Conversation

@spartan8806

Copy link
Copy Markdown
Contributor

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 actually remain, and BufferView::read() copied that many bytes without comparing against streamSize_. 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_ - start rather than start + count > streamSize_ so it can't itself overflow.

Verified against a clean checkout of master:

  • before — ASAN reports heap-buffer-overflow, READ of size 1, at CheckedFile.cpp:177
  • after — throws E57Exception under both ChecksumAll and ChecksumNone, exit 0, no ASAN report

Happy 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.

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.
@asmaloney

Copy link
Copy Markdown
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
asmaloney merged commit 0e1d480 into asmaloney:master Aug 12, 2026
12 checks passed
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>
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>
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