Skip to content

fix: UnionFields::from_iter should validate input - #11533

Merged
Jefffrey merged 3 commits into
apache:mainfrom
Jefffrey:union-fields-from-validate
Oct 15, 2026
Merged

Jefffrey merged 3 commits into
apache:mainfrom
Jefffrey:union-fields-from-validate

Conversation

@Jefffrey

@Jefffrey Jefffrey commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

  • None

Rationale for this change

Make it impossible to create an invalid UnionFields via safe APIs. This makes it easier for downstream uses of UnionFields (in other parts of the codebase), since they can rely on the data being valid, instead of needing to check each time.

What changes are included in this PR?

Make sure UnionFields::from_iter validates its input before construction a UnionFields, similar to UnionFields::try_new

Are these changes tested?

Added new unit test.

Are there any significant user-facing changes?

UnionFields::from_iter can now panic on invalid input data. This can be reachable via a collect() into a UnionFields for example.

@Jefffrey Jefffrey added the bug Squash those bugs label Oct 13, 2026
Self(iter.into_iter().collect())
let iter = iter.into_iter();
let (type_ids, fields): (Vec<i8>, Vec<FieldRef>) = iter.unzip();
Self::try_new(type_ids, fields).expect("invalid arguments passed")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunate that it introduces a panic, but this is better than letting in invalid data

@github-actions github-actions Bot added the arrow-core Core crates related to representing arrow data label Oct 13, 2026
/// - All type ids are unique
/// - All type ids are non-negative
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]

@Jefffrey Jefffrey Oct 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

identified by codex review, but having these serde derives still allows a loophole; i dont know the impact of removing them (if even possible)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jefffrey
Jefffrey added this pull request to the merge queue Oct 14, 2026
@Jefffrey

Copy link
Copy Markdown
Contributor Author

thanks @alamb

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 14, 2026
@alamb

alamb commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

etseidl pushed a commit to etseidl/arrow-rs that referenced this pull request Oct 15, 2026
…he#11562)

# Which issue does this PR close?

N/A

# Rationale for this change

The `audit` CI job is failing on main and on PRs (for example
https://github.com/apache/arrow-rs/actions/runs/38600959284/job/116002272430
on apache#11533) because four new RustSec advisories were published today
against `rustls`:

- [RUSTSEC-2026-0346](https://rustsec.org/advisories/RUSTSEC-2026-0346):
`Debug` impls for client session values expose TLS secrets
- [RUSTSEC-2026-0347](https://rustsec.org/advisories/RUSTSEC-2026-0347):
Buffered application data sent to outer server after ECH rejection
- [RUSTSEC-2026-0348](https://rustsec.org/advisories/RUSTSEC-2026-0348):
Brotli certificate decompression can allocate up to 1 GiB before
authentication
- [RUSTSEC-2026-0349](https://rustsec.org/advisories/RUSTSEC-2026-0349):
Unauthenticated ServerHello can downgrade later connections to classical
key exchange

All four are fixed in `rustls` 0.23.46.

# What changes are included in this PR?

`cargo update -p rustls`, which bumps `rustls` from 0.23.45 to 0.23.46
in `Cargo.lock`. No other changes.

# Are these changes tested?

I reproduced the failure locally with `cargo audit` on current main
(same four advisories), and confirmed `cargo audit` passes after this
change.

# Are there any user-facing changes?

No

Co-authored-by: Claude Fable 5.1 <[email protected]>
@Jefffrey
Jefffrey added this pull request to the merge queue Oct 15, 2026
Merged via the queue into apache:main with commit b2e2c2d Oct 15, 2026
34 checks passed
@Jefffrey
Jefffrey deleted the union-fields-from-validate branch October 15, 2026 05:16
Seanium pushed a commit to Seanium/arrow-rs that referenced this pull request Oct 18, 2026
…11638)

# Which issue does this PR close?

- Closes apache#11576.

# Rationale for this change

`UnionFields` derived `Deserialize`, so deserializing could build a
value with duplicate or negative type ids, skipping the checks that
apache#11533 added to the other constructors.

# What changes are included in this PR?

`Serialize` is still derived (transparent), but `Deserialize` is now
implemented by hand: it reads the same sequence of `(type_id, field)`
pairs and builds the value with `UnionFields::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 therefore
`Field` and `Schema`) derive serde and need `UnionFields` to support it.

# Are these changes tested?

Yes, two new tests in `fields.rs` (behind the `serde` feature, using
`postcard` like the existing `Field` serde tests): a round trip of a
valid `UnionFields`, 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 a `DataType::Union`
containing 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.

---------

Co-authored-by: ump45nose <[email protected]>
alamb pushed a commit that referenced this pull request Oct 19, 2026
alamb pushed a commit that referenced this pull request Oct 21, 2026
alamb added a commit that referenced this pull request Oct 21, 2026
…11726)

- Backport #11533
- For inclusion in #11666

Cherry-pick of
b2e2c2d

Co-authored-by: Jeffrey Vo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow-core Core crates related to representing arrow data bug Squash those bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants