Repository navigation
fix(arrow-schema): validate UnionFields when deserializing - #11638
Merged
Merged
Conversation
Jefffrey
reviewed
Oct 17, 2026
| let negative: Vec<(i8, FieldRef)> = vec![(0, Arc::clone(&field)), (-1, field)]; | ||
| let serialized = postcard::to_stdvec(&negative).unwrap(); | ||
| let err = postcard::from_bytes::<UnionFields>(&serialized).unwrap_err(); | ||
| assert!(matches!(err, postcard::Error::SerdeDeCustom), "{err:?}"); |
Contributor
There was a problem hiding this comment.
is it possible to assert some of the error message too?
Comment on lines
+323
to
+324
| /// Deserializes the same representation as `Serialize`, but goes through | ||
| /// [`UnionFields::try_new`] so the invariants above are enforced. |
Contributor
There was a problem hiding this comment.
Suggested change
| /// Deserializes the same representation as `Serialize`, but goes through | |
| /// [`UnionFields::try_new`] so the invariants above are enforced. | |
| // Manual implementation to enforce invariants per docstring above |
Jefffrey
approved these changes
Oct 18, 2026
Jefffrey
enabled auto-merge
October 18, 2026 02:16
This was referenced Oct 18, 2026
alamb
added a commit
that referenced
this pull request
Oct 20, 2026
…ializing (#11672) - Backport #11638 - For inclusion in #11664 Cherry-pick of a2b405f --------- Co-authored-by: ump45nose <[email protected]> Co-authored-by: ump45nose <[email protected]> Co-authored-by: Andrew Lamb <[email protected]>
alamb
added a commit
that referenced
this pull request
Oct 22, 2026
…ializing (#11760) - Backport #11638 - For inclusion in #11665 Cherry-pick of a2b405f Co-authored-by: ump45nose <[email protected]> Co-authored-by: ump45nose <[email protected]> Co-authored-by: Andrew Lamb <[email protected]>
alamb
pushed a commit
that referenced
this pull request
Oct 22, 2026
…ializing (#11813) - Backport #11638 - For inclusion in #11666 Cherry-pick of a2b405f Co-authored-by: ump45nose <[email protected]> Co-authored-by: ump45nose <[email protected]>
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.
Which issue does this PR close?
UnionFieldsserde allows bypass of validation #11576.Rationale for this change
UnionFieldsderivedDeserialize, so deserializing could build a value with duplicate or negative type ids, skipping the checks that #11533 added to the other constructors.What changes are included in this PR?
Serializeis still derived (transparent), butDeserializeis now implemented by hand: it reads the same sequence of(type_id, field)pairs and builds the value withUnionFields::try_new, returning a serde error if validation fails. The wire format doesn't change, so anything serialized before still deserializes as long as it was valid.I kept serde rather than removing it, since
DataType(and thereforeFieldandSchema) derive serde and needUnionFieldsto support it.Are these changes tested?
Yes, two new tests in
fields.rs(behind theserdefeature, usingpostcardlike the existingFieldserde tests): a round trip of a validUnionFields, and deserializing input with a duplicate type id and with a negative type id, both of which now fail. The second test fails without this change.Are there any significant user-facing changes?
Deserializing an invalid
UnionFields(or aDataType::Unioncontaining one) now returns an error instead of succeeding.AI disclosure: I used an AI coding assistant to write the change, the tests and this description, and I reviewed all of it.