serde_bser/mincode: validate wire-supplied lengths before indexing - #1420
Open
rootkiller6788 wants to merge 1 commit into
Open
serde_bser/mincode: validate wire-supplied lengths before indexing#1420rootkiller6788 wants to merge 1 commit into
rootkiller6788 wants to merge 1 commit into
Conversation
BSER and mincode deserializers take lengths directly from the encoded data and use them to index into buffers without validation, panicking on malformed input instead of returning an error. serde_bser: - Reject negative bytestring/utf8string lengths in read_bytes instead of casting them to a huge usize. - Grow the IoRead scratch buffer in bounded chunks instead of pre-allocating the wire length, avoiding a capacity-overflow panic when the declared length is far larger than the stream. mincode: - Reject string/bytes lengths that exceed the remaining input before calling split_at. - Reject empty or truncated chars instead of indexing out of bounds. Add regression tests for each panic.
|
This pull request has been imported. If you are a Meta employee, you can view this in D116931726. (Because this pull request was imported automatically, there will not be any future comments.) |
rootkiller6788
marked this pull request as ready for review
August 22, 2026 14:52
Author
|
The PR has been imported internally as D116931726. |
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.
Summary
Closes #1417.
Both
serde_bser(Watchman's BSER codec) andmincodetake a length from the encoded data and use it to index into a buffer without validating it against the remaining input, so malformed/truncated payloads panic instead of returning a deserialization error.serde_bser
Bunser::read_bytescasts a signed wire length straight tousize. A negative length (e.g.BSER_INT8 = -1) becomesusize::MAX, making the slice reader overflow onindex + len(debug: attempt to add with overflow; release: inverted-range slice panic) and making the stream reader callscratch.resize(huge, 0)(capacity overflow). The fix rejectslen < 0inread_byteswith a newError::DeNegativeLengthvariant.IoRead::next_bytesgrew the scratch buffer to the full wire length up front. The fix grows it in bounded 4 KiB chunks, so a declared length far larger than the stream yields an EOF error instead of a capacity-overflow panic.mincode
Deserializer::read_slicecalledsplit_at(len)with a VLQ length read from the data; a length larger than the remaining buffer panicked with mid > len. It now returns an error.deserialize_charindexedself.bytes[0]without checking for an empty buffer and sliced&self.bytes[..width]withwidthtaken from the UTF-8 lead byte without checking the remaining length. Both paths now return an error.Test plan
cargo testinwatchman/rust/serde_bser(15 pre-existing + 2 new tests pass, debug and release).cargo testineden/scm/lib/mincode(1 pre-existing roundtrip + 3 new tests pass).