mbutrovich opened a new issue, #12143:
URL: https://github.com/apache/arrow-rs/issues/12143

   **Describe the bug**
   
   The rustdoc of 
[`GenericByteArray::new_repeated`](https://github.com/apache/arrow-rs/blob/16ac7c8878c470acd509a12f5db0524a92ee71e0/arrow-array/src/array/byte_array.rs#L180-L185)
 says it panics "if value's length multiplied by `repeat_count` overflows 
usize". It also panics when that product fits in `usize` but not in the offset 
type, because it builds its offsets with 
[`OffsetBuffer::from_repeated_length`](https://github.com/apache/arrow-rs/blob/16ac7c8878c470acd509a12f5db0524a92ee71e0/arrow-buffer/src/buffer/offset.rs#L177-L179),
 which panics on offset overflow. For `StringArray` and `BinaryArray` that is 
any total above `i32::MAX` bytes. `new_repeated` has no fallible form, though 
[`OffsetBuffer::try_from_repeated_length`](https://github.com/apache/arrow-rs/blob/16ac7c8878c470acd509a12f5db0524a92ee71e0/arrow-buffer/src/buffer/offset.rs#L194)
 exists.
   
   **To Reproduce**
   
   ```rust
   use arrow_array::{Array, StringArray};
   
   fn main() {
       // 2^20 bytes repeated 2^11 times is 2^31 bytes, one past i32::MAX. The
       // product fits in usize, so the rustdoc documents no panic.
       let value = "a".repeat(1 << 20);
       let a = StringArray::new_repeated(&value, 1 << 11);
       // panics: offset overflow: 2147483648 does not fit in i32
       println!("{} rows", a.len());
   }
   ```
   
   **Expected behavior**
   
   The rustdoc names the offset overflow as a panic. Should there also be a 
fallible `try_new_repeated` that returns an `ArrowError`, as 
`OffsetBuffer::try_from_repeated_length` does for the offsets? Callers that 
return a `Result` could then use it. DataFusion's 
`ScalarValue::to_array_of_size` calls `new_repeated` for `Utf8` and `Binary` 
scalars, so a query panics where it should fail.
   
   **Additional context**
   
   Property-based tests found this through DataFusion's `repeat` on DataFusion 
`main` at 14b3edd9a3, which builds on arrow 60.1.0. The reproduction panics on 
arrow-rs `main` at 16ac7c8878.


-- 
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]

Reply via email to