-
Notifications
You must be signed in to change notification settings - Fork 18
Fix bounds check in Reader::view_entry_at to prevent buffer overruns #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
5
commits into
main
Choose a base branch
from
copilot/fix-63
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1dfa6e4
Initial plan
Copilot f9ce71d
Fix bounds check in Reader::view_entry_at to account for object size
Copilot 4e96a65
Fix assertion logic: use < instead of <= for byte_offset bounds check
Copilot 8183830
Add test demonstrating buffer overrun fix
Copilot 7016b06
Add partition bounds validation to prevent buffer overruns at root cause
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
byte_offset <= contents.size()will allow buffer overrun.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're absolutely right about
<=allowing buffer overrun. The current code (after 4e96a65) correctly uses<which is semantically appropriate since we need the offset to be a valid index.Created a comprehensive test (8183830) that demonstrates the fix addresses the original issue:
Original assertion was insufficient: For a 16-byte buffer reading a 4-byte object at offset 15:
15 < 16→ PASS (but reads bytes [15,16,17,18] in buffer [0-15] → overrun)15 < 16 && (16-15) >= 4→true && false→ FAIL (correctly prevents overrun)Valid accesses still work: Reading 4-byte object at offset 12:
12 < 16 && (16-12) >= 4→true && true→ PASS (allows valid access)The test proves the new assertion prevents buffer overruns while maintaining compatibility with valid reads.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You strengthened the assertion, which is good, but that is not the root cause of the failure. The assertion is only signaling a symptom, a sign that an error occurred much earlier. Keep the assertion, and keep looking for the root cause of the bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're absolutely right. The assertion was correctly catching a symptom of corruption happening earlier in the process.
I've identified the root cause: partition data read from IFC files wasn't being validated for bounds safety. The issue occurs when
Reader::read_table_of_contents()reads partition summaries containingoffset,cardinality, andentry_sizefields that can be corrupted/malformed. Thetell()method then calculates invalid offsets usingoffset + index * entry_size, which eventually leads to the assertion failure.The fix (7016b06) adds comprehensive partition bounds validation in
read_table_of_contents()to catch invalid data at the source:This prevents invalid
ByteOffsetvalues from ever being calculated, addressing the root cause while keeping the strengthened assertion as a safety net.