AndreaBozzo opened a new issue, #11388:
URL: https://github.com/apache/arrow-rs/issues/11388
### Describe the bug
`ArrowArrayStreamReader` panics when an imported C stream has a NULL
`get_schema` or `get_next` callback. `try_new` returns
`ArrowError::CDataInterface` for a released stream, but then calls
`get_schema.unwrap()`, and `next()` calls `get_next.unwrap()`
(`arrow-array/src/ffi_stream.rs:443` and `:497` on main, `:371` and `:425` in
60.0.0). A NULL `get_last_error` is already handled: the reader returns the
error without a producer message.
The C Stream Interface marks both callbacks *Mandatory*, so a NULL one is a
producer error, and the reader should report it as one. If the reader is then
re-exported with `FFI_ArrowArrayStream::new`, the panic happens inside the
exported `extern "C"` `get_next` and aborts the process, which is the situation
described in #8913.
### To Reproduce
Against main (103ebe754), with the `ffi` feature:
```rust
use std::ffi::c_int;
use arrow::datatypes::{DataType, Field, Schema};
use arrow::ffi::FFI_ArrowSchema;
use arrow::ffi_stream::{ArrowArrayStreamReader, FFI_ArrowArrayStream};
unsafe extern "C" fn get_schema(_: *mut FFI_ArrowArrayStream, out: *mut
FFI_ArrowSchema) -> c_int {
let schema = Schema::new(vec![Field::new("a", DataType::Int32, false)]);
unsafe { out.write(FFI_ArrowSchema::try_from(&schema).unwrap()) };
0
}
unsafe extern "C" fn release(stream: *mut FFI_ArrowArrayStream) {
unsafe { (*stream).set_release(None) };
}
fn main() {
// Stands in for a C producer that leaves get_next NULL.
let stream = unsafe {
FFI_ArrowArrayStream::new_unchecked(Some(get_schema), None, None,
Some(release), std::ptr::null_mut())
};
let mut reader = ArrowArrayStreamReader::try_new(stream).unwrap();
let _ = reader.next(); // panics: called `Option::unwrap()` on a `None`
value
}
```
Passing `None` for `get_schema` as well makes `try_new` itself panic, at
`ffi_stream.rs:443`.
### Expected behavior
Both cases return `ArrowError::CDataInterface`, as `try_new` already does
for a released stream, in line with #6737.
### Additional context
Found while running C Stream consumers against defective producers with
[arrow-abi-doctor](https://github.com/AndreaBozzo/arrow-abi-doctor). I am happy
to open the PR: replace both unwraps with `CDataInterface` errors and add a
test for each callback.
--
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]