This is an automated email from the ASF dual-hosted git repository.
hcr pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/mahout.git
The following commit(s) were added to refs/heads/main by this push:
new 762d7b8df fix(qdp): Replace panic with Result error for Arrow IPC
capacity overflow (#960)
762d7b8df is described below
commit 762d7b8df6713ead7d091f2a5a1cb4439fc6c539
Author: Shivam Mittal <[email protected]>
AuthorDate: Wed Jan 28 20:12:33 2026 +0530
fix(qdp): Replace panic with Result error for Arrow IPC capacity overflow
(#960)
Replace `.expect()` with `.ok_or_else()` for overflow checks in Arrow IPC
reader to return a proper `Result` error instead of panicking. This affects:
1. FixedSizeList branch (line 117-119): `checked_mul().expect()` ->
`checked_mul().ok_or_else()?`
2. List branch (line 164): `current_size * list_array.len()` ->
`checked_mul().ok_or_else()?`
On 32-bit systems, large quantum state vectors (e.g., 20 qubits = 1M
elements)
combined with large batch sizes can overflow `usize`. This change allows
callers
to handle the error gracefully instead of crashing.
Fixes #941
---
qdp/qdp-core/src/readers/arrow_ipc.rs | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/qdp/qdp-core/src/readers/arrow_ipc.rs
b/qdp/qdp-core/src/readers/arrow_ipc.rs
index 4809cb3d5..57064f129 100644
--- a/qdp/qdp-core/src/readers/arrow_ipc.rs
+++ b/qdp/qdp-core/src/readers/arrow_ipc.rs
@@ -114,9 +114,14 @@ impl DataReader for ArrowIPCReader {
}
} else {
sample_size = Some(current_size);
- let new_capacity = current_size
- .checked_mul(batch.num_rows())
- .expect("Capacity overflowed usize");
+ let new_capacity =
+
current_size.checked_mul(batch.num_rows()).ok_or_else(|| {
+ MahoutError::InvalidInput(format!(
+ "FixedSizeList capacity overflow: {} * {}
would overflow usize",
+ current_size,
+ batch.num_rows()
+ ))
+ })?;
all_data.reserve(new_capacity);
}
@@ -161,7 +166,15 @@ impl DataReader for ArrowIPCReader {
}
} else {
sample_size = Some(current_size);
- all_data.reserve(current_size * list_array.len());
+ let new_capacity =
+
current_size.checked_mul(list_array.len()).ok_or_else(|| {
+ MahoutError::InvalidInput(format!(
+ "List capacity overflow: {} * {} would
overflow usize",
+ current_size,
+ list_array.len()
+ ))
+ })?;
+ all_data.reserve(new_capacity);
}
if float_array.null_count() == 0 {