sam-1112 opened a new issue, #27623:
URL: https://github.com/apache/datafusion/issues/27623

   ### Describe the bug
   
   `repeat` checks each output value against the `Utf8` size limit, but does 
not check the cumulative output size before allocating the output buffer.
   
   Consequently, individually valid rows can produce an array whose total 
output exceeds `i32::MAX` bytes:
   
   - If allocation succeeds, appending values panics with `byte array offset 
overflow`.
   - If the allocator refuses the reservation, the process aborts instead of 
returning a DataFusion error.
   
   This affects downstream Comet workloads tracked in 
[apache/datafusion-comet#7500](https://github.com/apache/datafusion-comet/issues/7500).
   
   ### To Reproduce
   
   Add this test inside the existing tests module in 
`datafusion/functions/src/string/repeat.rs`:
   ```
   #[test]
   fn test_repeat_utf8_total_output_overflow() {
       use std::sync::Arc;
   
       use arrow::array::{ArrayRef, Int64Array, StringArray};
   
       let strings: ArrayRef =
           Arc::new(StringArray::from(vec!["a", "a"]));
       let counts: ArrayRef =
           Arc::new(Int64Array::from(vec![1_i64 << 30; 2]));
   
       // Each row produces 1 GiB, within the per-value limit.
       // The total is 2 GiB, exceeding i32::MAX by one byte.
       let result = super::repeat(&strings, &counts);
   
       assert!(result.is_err());
   }
   ```
   The call panics before reaching the assertion:
   ```
   byte array offset overflow: Execution("byte array offset overflow: output 
size exceeds 2147483647 bytes")
   ```
   This reproducer requires several GiB of memory because the output is 
allocated and materialized before the panic.
   
   The excessive reservation case from Comet is:
   
   Input: 8192 Utf8 rows, each containing 100 ASCII bytes
   Count: 1,000,000
   Total output: 819,200,000,000 bytes
   
   Each row passes the size check, and `repeat` attempts to reserve the entire 
output. In an isolated test process with an allocator that rejects requests 
above 8 GiB, this produced:
   
   memory allocation of 819200000000 bytes failed
   
   The process terminated with `SIGABRT`.
   
   
   ### Expected behavior
   
   Check the cumulative `Utf8` output size against `i32::MAX` before allocating 
the output buffer, and return an error when it exceeds the limit.
   
   ### Additional context
   
   - [#26957](https://github.com/apache/datafusion/pull/26957), which fixes 
[#26948](https://github.com/apache/datafusion/issues/26948), adds a cumulative 
size check for `LargeUtf8`. The `Utf8` branch still lacks this check.
   
   ### Willingness to contribute
   
   I would like to contribute a fix for this bug, but request guidance from the 
DataFusion community


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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to