This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/main by this push:
new 7a1ab97273 fix(arrow-array): avoid null bitmap allocation in
non-nullable StructArray field validation (#12124)
7a1ab97273 is described below
commit 7a1ab972737ba523c8054bb20cf60be7065675e1
Author: llxgdtop <[email protected]>
AuthorDate: Tue Nov 10 19:05:45 2026 +0000
fix(arrow-array): avoid null bitmap allocation in non-nullable StructArray
field validation (#12124)
# Which issue does this PR close?
- Closes #11848
# Rationale for this change
`StructArray::try_new_with_length` validated non-nullable fields by
materializing the child's logical null buffer before doing anything
else. A `NullArray` stores no data, so `NullArray::new(usize::MAX)`
costs nothing to build — but its logical null buffer is proportional
to the length, and the validation panics on a ~2.3 EB allocation
instead of returning an `InvalidArgumentError`.
# What changes are included in this PR?
- When the struct has no nulls of its own, check
`logical_null_count()` instead, which `NullArray` implements in O(1).
- Only materialize `logical_nulls()` for the bit-level `contains`
comparison when parent nulls are present.
- The check is otherwise equivalent: `contains()` already returns
`true` for a buffer with no nulls, so the separate `null_count > 0`
test is no longer needed.
# Are these changes tested?
Yes. A new regression test builds a `StructArray` with a non-nullable
field backed by `NullArray::new(usize::MAX)`. It panics with a 2.25 EB
allocation failure on `main`, and returns `InvalidArgumentError` with
this change. `cargo test -p arrow-array` (754 unit + 208 doc tests),
clippy `-D warnings` and `cargo fmt --check` all pass.
# Are there any significant user-facing changes?
No. The only behavioural difference is that this invalid input now
surfaces as an error instead of a panic.
---
This PR was prepared with AI assistance: I used it to help me
understand the validation code and the root cause, and to draft this
description. I understand the change and stand behind it.
All three failing jobs fail in environment setup steps (`Install
HawkEye`,
Archery `Build`, `Setup Python`) — every code check passes.
The HawkEye one looks like a tooling issue rather than anything on this
branch: hawkeye 7.3.0 was released on Nov 2 and `install-action` picks
up
the latest release. I installed the same version locally from crates.io
and ran `hawkeye check --fail-on-unknown`: 862 files, 0 conflicts, exit
0.
So the prebuilt 7.3.0 binaries may be the problem.
---
arrow-array/src/array/struct_array.rs | 38 ++++++++++++++++++++++++++---------
1 file changed, 28 insertions(+), 10 deletions(-)
diff --git a/arrow-array/src/array/struct_array.rs
b/arrow-array/src/array/struct_array.rs
index 605ce61de2..0a707dbbc9 100644
--- a/arrow-array/src/array/struct_array.rs
+++ b/arrow-array/src/array/struct_array.rs
@@ -153,15 +153,17 @@ impl StructArray {
)));
}
- if !f.is_nullable()
- && let Some(a) = a.logical_nulls()
- && nulls.as_ref().is_none_or(|n| !n.contains(&a))
- && a.null_count() > 0
- {
- return Err(ArrowError::InvalidArgumentError(format!(
- "Found unmasked nulls for non-nullable StructArray field
{:?}",
- f.name()
- )));
+ if !f.is_nullable() {
+ let unmasked = match nulls.as_ref() {
+ None => a.logical_null_count() > 0,
+ Some(n) => a.logical_nulls().is_some_and(|ln|
!n.contains(&ln)),
+ };
+ if unmasked {
+ return Err(ArrowError::InvalidArgumentError(format!(
+ "Found unmasked nulls for non-nullable StructArray
field {:?}",
+ f.name()
+ )));
+ }
}
}
@@ -618,7 +620,7 @@ mod tests {
use super::*;
use crate::{
- BooleanArray, Float32Array, Float64Array, Int32Array, Int64Array,
StringArray,
+ BooleanArray, Float32Array, Float64Array, Int32Array, Int64Array,
NullArray, StringArray,
cast::AsArray, types::Int32Type,
};
use arrow_buffer::ToByteSlice;
@@ -1145,6 +1147,22 @@ mod tests {
)]));
}
+ #[test]
+ fn test_struct_array_non_nullable_null_array_with_max_length() {
+ // A non-nullable field backed by a NullArray of `usize::MAX` length
+ // should be rejected with an error, not panic trying to materialize
+ // a null buffer of ~2.3 EB
+ let fields = Fields::from(vec![Field::new("a", DataType::Null,
false)]);
+ let array = Arc::new(NullArray::new(usize::MAX)) as ArrayRef;
+
+ let err =
+ StructArray::try_new_with_length(fields, vec![array], None,
usize::MAX).unwrap_err();
+ assert_eq!(
+ err.to_string(),
+ "Invalid argument error: Found unmasked nulls for non-nullable
StructArray field \"a\"",
+ );
+ }
+
#[test]
fn test_struct_array_fmt_debug() {
let arr = StructArray::new(