Repository navigation
Reject extra array elements for fixed-length types (text and Value) - #484
Merged
Merged
Conversation
Member
|
will need a re-base due to conflicts, otherwise 🚀 |
A tuple, array, tuple struct or struct read from an array asks the
`SeqAccess` for exactly as many elements as it has and then stops. The
elements it left unread stayed on the tape and were read as the values
that follow the array, so data silently shifted:
from_slice::<((u8, u8), u8)>("[[1,2,3],4]") Ok(((1, 2), 3))
from_slice::<(u8, (u8,), u8)>("[1,[2,99,98],3]") Ok((1, (2,), 99))
from_slice::<Vec<(u8, u8)>>("[[1,2,[9,9]],[4,5]]") Ok([(1, 2), (9, 9)])
and in other shapes failed with unrelated errors (`ExpectedArray`,
`ExpectedString`). serde_json and sonic-rs reject all of these.
(`from_owned_value` ignores the extra elements without shifting the
following values; it is not changed here.)
After the visitor returns, the remaining element count must be 0;
otherwise it is an `invalid_length` error, as in
`serde::de::value::SeqDeserializer::end` and serde_json's
`visit_array`. The same check covers objects (a visitor that stops
reading members early).
Test: `fixed_length_sequences_reject_extra_elements` (fails before this
change).
Found by a three-way differential fuzzer (serde_json, simd-json,
sonic-rs).
yuxi-liu-wired
force-pushed
the
pr/extra-elements
branch
from
October 4, 2026 18:54
76bdf17 to
7ce1171
Compare
Contributor
Author
|
Rebased on main. Since #488 already brought in the Value side of this ( |
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.
fix: reject extra array elements for fixed-length types
A tuple, array, tuple struct or struct read from an array asks the
SeqAccessfor exactly as many elements as it has, then stops. The elements it left unread stayed on the tape and were read as the values after the array, so the data silently shifted:In other shapes it failed with unrelated errors (
ExpectedArray,ExpectedString). serde_json and sonic-rs reject all of these.After the visitor returns, the remaining element count must be 0. Otherwise it is an
invalid_lengtherror, as inserde::de::value::SeqDeserializer::endand serde_json'svisit_array. The same check covers objects, where a visitor stops reading members early.The Value deserializers got the same check in #488.
Tests:
fixed_length_sequences_reject_extra_elementstuple_variants_reject_extra_elements(text and every Value, as asked in review)Both fail on main and pass with the change. The full test suite passes, and
cargo fmt --checkand clippy are clean.Found with a differential fuzzer comparing serde_json, simd-json, sonic-rs and jiter.