sunchao opened a new issue, #10845:
URL: https://github.com/apache/arrow-rs/issues/10845
### Describe the bug
`UnionArray::try_new` narrows child lengths from `usize` to `i32` while
building its type-ID lookup. A valid dense Union with a child longer than
`i32::MAX` is rejected even when every selected offset fits in `i32` and is in
bounds.
At a child length of `i32::MAX + 1`, the truncated length collides with the
`i32::MIN` sentinel for a missing type ID, producing `Type Ids values must
match one of the field type ids`. Larger child lengths can instead trigger the
offset-bounds error.
### To reproduce
This uses a `NullArray`, so it does not allocate billions of values:
```rust
use std::sync::Arc;
use arrow_array::{NullArray, UnionArray};
use arrow_schema::{DataType, Field, UnionFields};
let fields = UnionFields::try_new(
[3],
[Field::new("nulls", DataType::Null, true)],
).unwrap();
let result = UnionArray::try_new(
fields,
vec![3, 3].into(),
Some(vec![0, i32::MAX].into()),
vec![Arc::new(NullArray::new(i32::MAX as usize + 1))],
);
assert!(result.is_ok());
```
Reproduced on `900ec3ee38276ab651e210c4a85b38f8a8a61bcf`.
### Expected behavior
The Union should be accepted. Its offsets are representable and point inside
the child. Child length and type-ID presence should be checked without
truncating the length.
### Additional context
AI assistance: Codex helped investigate the implementation and generate the
reproduction and this report.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]