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

   ### Describe the bug
   
   An empty `StringArray` that arrow-rs itself slices and exports through the C 
Data Interface imports as `ArrayData` that fails `validate_full`. This is a 
remaining case of #10910, which #10916 fixed for imports with a nonzero 
`offset`.
   
   ### To Reproduce
   
   ```rust
   use std::sync::Arc;
   use arrow_array::{Array, ArrayRef, StringArray};
   
   fn main() {
       let a: ArrayRef = Arc::new(StringArray::from(vec!["ab", "c"]));
       let empty = a.slice(1, 0);
       let (array, schema) = 
arrow_array::ffi::to_ffi(&empty.to_data()).unwrap();
       let imported = unsafe { arrow_array::ffi::from_ffi(array, &schema) 
}.unwrap();
       println!("{:?}", imported.validate_full());
       // Err(InvalidArgumentError("First offset 2 of Utf8 is larger than 
values length 0"))
   }
   ```
   
   ### Expected behavior
   
   The imported array is valid, as the exported one is.
   
   ### Additional context
   
   `StringArray::slice(1, 0)` keeps a single offset of 2 and exports the array 
with `offset` 0 and `length` 0. The importer then sizes the values buffer as 0 
([ffi.rs](https://github.com/apache/arrow-rs/blob/72887ed91c80002bb7ec755ce1e964bab07bebea/arrow-array/src/ffi.rs#L473-L484)).
 Its comment says the single offset "can be an arbitrary value from the 
producer", but `validate_full` rejects a first offset larger than the values 
buffer. #10910 says this shape is not reachable through arrow-rs's own slicing, 
and this reproduction shows it is.
   
   No values are wrong, as the array is empty. The impact is on code that 
validates imported data, which rejects an array arrow-rs exported itself.
   
   Either the importer could normalize the offsets of an empty array to `[0]`, 
or it could size the values buffer from the offset that is present.
   
   Found with property-based tests that build arrays in every physical layout 
the Arrow format allows.
   


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