Conversation
* encapsulate buffer reads and address arithmetic behind a checked cursor * route Reader, VectorReader, and MapReader through the cursor * reject invalid ranges, overflow, unterminated keys, and mismatched map key/value lengths * add 15 malformed-input tests
Author
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.
The Problem
Many of the public API
Result<T, Error>return values are fragile. Malformed input can bypass theErrorcontract and panic, wrap buffer positions, or decode truncated data incorrectly.reader/mod.rs:307- arithmetic overflow.:326- unchecked indexing -> panic.:339- unterminated key accepted.:356- arithmetic overflow.:369- arithmetic overflow.:390- mismatched map key/value lengths accepted (was a TODO).:604,:606- unchecked indexing -> panic.:611,:616,:621- truncated integer read returns0.:621- W64 truncation on 32-bit.reader/vector.rs:55,:58- arithmetic overflow.:73- arithmetic overflow.reader/map.rs:83- unterminated map key accepted.:91,:92- arithmetic overflow.:94- reports malformed offsets asKeyNotFoundinstead ofFlexbufferOutOfBounds.:118,:119- arithmetic overflow.The Change
Three approaches were considered:
No breaking changes. Public API and default behavior are unchanged.
Testing
Added 15 new integration tests that cover all relevant bugs listed above.
NOTE: 32-bit specific tests were excluded as active Rust CI targets are 64-bit.
Ran
cargo teston both branches, 0/15 PASSED on old code, 15/15 PASSED on new code.All existing tests still pass.