Fix panic and add tests#310
Closed
ss-es wants to merge 9 commits into
Closed
Conversation
…ze-panic Fix deserialization panics
Cover BitVec/BitBox deserialization of tampered bincode buffers where head + bits exceeds the data capacity. The head + bits overflow cases currently abort (set_len assert + Vec::from_raw_parts UB in Drop) and fail until the deserializer validates head + bits against capacity. Adds proptest dev-dependency for the capacity-invariant property test.
BitVec/BitBox deserialization checked only bits > capacity (Vec capacity, head ignored), so a tampered head + bits exceeding the live buffer reached set_len and aborted (assert + Vec::from_raw_parts UB in Drop). Validate head + bits <= vec.len() * bits_of::<T>() and return BitSpanError::TooLong otherwise. Un-ignores the four regression/property tests.
fuzz_mutated_valid_buffer overwrites random bytes of a valid buffer; fuzz_arbitrary_bytes feeds raw bytes. Both assert deserialization never panics. Verified over 200k cases each.
The error path built BitSpan::new(addr, head, bits).unwrap_err(); when try_from_vec fails (bit-length exceeds REGION_MAX_BITS) but the deserialized bits is small, BitSpan::new returns Ok and unwrap_err panics. Return BitSpanError::TooLong(live) directly, where live is the overflowing length.
This reverts commit 46ac849.
Author
|
closed for #311 (squashing the commits) |
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.
Fixes a panic in the
Deserializeimplementation and adds tests