This is an automated email from the ASF dual-hosted git repository.
xudong963 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 002426087e Replace interleave overflow panic with error (#9549)
002426087e is described below
commit 002426087ea9106b616194a5d0942aedba2bc884
Author: xudong.w <[email protected]>
AuthorDate: Sat Mar 14 22:18:18 2026 +0800
Replace interleave overflow panic with error (#9549)
# Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax.
-->
- Closes #NNN.
# Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.
-->
# What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->
Replace interleave overflow panic with error
# Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
-->
Yes UT
# Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
If there are any breaking changes to public APIs, please call them out.
-->
---
arrow-select/src/interleave.rs | 46 ++++++++++++++++++++++++++++++++++++------
1 file changed, 40 insertions(+), 6 deletions(-)
diff --git a/arrow-select/src/interleave.rs b/arrow-select/src/interleave.rs
index 6598a5eb0d..be4e98ffcc 100644
--- a/arrow-select/src/interleave.rs
+++ b/arrow-select/src/interleave.rs
@@ -173,12 +173,15 @@ fn interleave_bytes<T: ByteArrayType>(
let mut capacity = 0;
let mut offsets = Vec::with_capacity(indices.len() + 1);
offsets.push(T::Offset::from_usize(0).unwrap());
- offsets.extend(indices.iter().map(|(a, b)| {
+ for (a, b) in indices {
let o = interleaved.arrays[*a].value_offsets();
let element_len = o[*b + 1].as_usize() - o[*b].as_usize();
capacity += element_len;
- T::Offset::from_usize(capacity).expect("overflow")
- }));
+ offsets.push(
+ T::Offset::from_usize(capacity)
+ .ok_or_else(|| ArrowError::OffsetOverflowError(capacity))?,
+ );
+ }
let mut values = Vec::with_capacity(capacity);
for (a, b) in indices {
@@ -331,12 +334,14 @@ fn interleave_list<O: OffsetSizeTrait>(
let mut capacity = 0usize;
let mut offsets = Vec::with_capacity(indices.len() + 1);
offsets.push(O::from_usize(0).unwrap());
- offsets.extend(indices.iter().map(|(array, row)| {
+ for (array, row) in indices {
let o = interleaved.arrays[*array].value_offsets();
let element_len = o[*row + 1].as_usize() - o[*row].as_usize();
capacity += element_len;
- O::from_usize(capacity).expect("offset overflow")
- }));
+ offsets.push(
+ O::from_usize(capacity).ok_or_else(||
ArrowError::OffsetOverflowError(capacity))?,
+ );
+ }
let mut child_indices = Vec::with_capacity(capacity);
for (array, row) in indices {
@@ -1414,4 +1419,33 @@ mod tests {
]
);
}
+
+ #[test]
+ fn test_interleave_bytes_offset_overflow() {
+ let indices: Vec<(usize, usize)> = vec![(0, 0); (i32::MAX >> 4) as
usize];
+ let text = ('a'..='z').collect::<String>();
+ let values = StringArray::from(vec![Some(text)]);
+ assert!(matches!(
+ interleave(&[&values], &indices),
+ Err(ArrowError::OffsetOverflowError(_))
+ ));
+ }
+
+ #[test]
+ fn test_interleave_list_offset_overflow() {
+ // Build a ListArray<i32> with a single row containing many elements
+ let mut builder = GenericListBuilder::<i32,
_>::new(Int32Builder::new());
+ for i in 0..32 {
+ builder.values().append_value(i);
+ }
+ builder.append(true);
+ let list = builder.finish();
+
+ // Interleave enough copies to overflow i32 offsets
+ let indices: Vec<(usize, usize)> = vec![(0, 0); (i32::MAX as usize /
32) + 1];
+ assert!(matches!(
+ interleave(&[&list], &indices),
+ Err(ArrowError::OffsetOverflowError(_))
+ ));
+ }
}