You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "Manishearth (via GitHub)" <gi...@apache.org> on 2026/07/01 16:12:32 UTC

[I] FFI_ArrowArrayStream + ArrowArrayStreamReader::try_new is technically unsound [arrow-rs]

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

   This is a minor technical unsoundness that is likely to never come up in real usage of this crate.
   
   [`FFI_ArrowArrayStream`](https://docs.rs/arrow-array/latest/arrow_array/ffi_stream/struct.FFI_ArrowArrayStream.html) has public fields, including raw pointer fields. They can be set to whatever you want in safe Rust code.
   
   [`ArrowArrayStreamReader::try_new()`](https://docs.rs/arrow-array/latest/arrow_array/ffi_stream/struct.ArrowArrayStreamReader.html#method.try_new) takes one of these, and [internally dereferences some of the pointers](https://docs.rs/arrow-array/latest/src/arrow_array/ffi_stream.rs.html#292-305).
   
   This means you can technically have UB if you fill an `FFI_ArrowArrayStream` with garbage and then pass it to `ArrowArrayStreamReader::try_new()`.
   
   In practice, nobody's going to do that; folks will be populating the FFI type over FFI (at which point it's no longer Rust's problem).
   
   But perhaps `ArrowArrayStreamReader::try_new()` should be `unsafe`, or `FFI_ArrowArrayStream` should have private fields.
   
   I don't think this is the only such type in the crate, but it's the first one that my agentic audit noticed.


-- 
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: github-unsubscribe@arrow.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] FFI_ArrowArrayStream + ArrowArrayStreamReader::try_new is technically unsound [arrow-rs]

Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey commented on issue #10253:
URL: https://github.com/apache/arrow-rs/issues/10253#issuecomment-5067325632

   im not as acquainted with the ffi side of things, but whats stated here makes sense. given it seems like a minor issue i suppose we can just wait for the next major release.
   
   that being said, i believe a bigger issue is that using `release` in the drop implementation has the same issue but with no easy way to slap an `unsafe` on it to make it as such 🤔 
   
   https://github.com/apache/arrow-rs/blob/f7dfcd25aabeb01641fe4b6c35ab964fdf0b24aa/arrow-array/src/ffi_stream.rs#L99-L111
   
   https://github.com/apache/arrow-rs/blob/f7dfcd25aabeb01641fe4b6c35ab964fdf0b24aa/arrow-array/src/ffi_stream.rs#L164-L171


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] FFI_ArrowArrayStream + ArrowArrayStreamReader::try_new is technically unsound [arrow-rs]

Posted by "bit2swaz (via GitHub)" <gi...@apache.org>.
bit2swaz commented on issue #10253:
URL: https://github.com/apache/arrow-rs/issues/10253#issuecomment-5069931240

   o shi yeah, hadnt thought about Drop. and i do agree, slapping `unsafe` on `try_new` doesnt really close that vector. Drop gets called implicitly and you cant mark `drop` unsafe
   
   the way i see it, the real fix is making the fields private. that way you cant construct an `FFI_ArrowArrayStream` with garbage callbacks in safe Rust at all which kills both the `try_new` problem and the Drop problem at the root. layout stays `#[repr(C)]` so external C producers arent affected as theyd still pass via `from_raw` which is already `unsafe`, and the the Rust-side constructors (`new`, `empty`) stay safe
   
   tho that does mean my current PR is at best a half-fix. happy to extend it, OR close it and redo it properly in one shot, whatever works for you. what do you say?


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] FFI_ArrowArrayStream + ArrowArrayStreamReader::try_new is technically unsound [arrow-rs]

Posted by "bit2swaz (via GitHub)" <gi...@apache.org>.
bit2swaz commented on issue #10253:
URL: https://github.com/apache/arrow-rs/issues/10253#issuecomment-5070335544

   yeah makes sense. if the goal is a broader fix, the real lever is making the fields private across all three structs (`FFI_ArrowSchema`, `FFI_ArrowArray`, `FFI_ArrowArrayStream`). each one has the same pattern: public fields, a `release` fn pointer called from `Drop`, and no way to mark `drop` unsafe. private fields kill the whole problem at the root since you cant construct a garbage instance in safe Rust at all
   
   ill be closing the current draft PR as it only covers `try_new` on one struct which is now the wrong scope. will open a proper issue + PR covering all three if thats alright


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] FFI_ArrowArrayStream + ArrowArrayStreamReader::try_new is technically unsound [arrow-rs]

Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey commented on issue #10253:
URL: https://github.com/apache/arrow-rs/issues/10253#issuecomment-5070181698

   it would be good to take this opportunity to think of a broader fix indeed
   
   especially as other structs are prone to the same issue (e.g. [FFI_ArrowArray](https://docs.rs/arrow/latest/arrow/array/ffi/struct.FFI_ArrowArray.html))


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] FFI_ArrowArrayStream + ArrowArrayStreamReader::try_new is technically unsound [arrow-rs]

Posted by "bit2swaz (via GitHub)" <gi...@apache.org>.
bit2swaz commented on issue #10253:
URL: https://github.com/apache/arrow-rs/issues/10253#issuecomment-5062000279

   confirmed. `try_new` is safe but calls `get_stream_schema` which derefs and calls the caller's `get_schema` fn pointer. every field of `FFI_ArrowArrayStream` is public so safe code can pass a stream with garbage callbacks and hit UB without ever writing `unsafe`. the `release.is_none()` check only catches an already-released stream
   
   imo the simplest fix is making `try_new` `unsafe` with a `# Safety` note. both `from_raw`s in the same file are already `unsafe` for this exact reason, so this just brings the last door in line. the real callers (arrow-pyarrow) already get their stream from `from_raw` / `_export_to_c` so they only need an `unsafe` block. private fields would work too but that breaks the `#[repr(C)]` ABI that external producers fill for no extra soundness
   
   its a breaking change so it wants a major release. @Jefffrey any preference on the fix and which milestone?


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] FFI_ArrowArrayStream + ArrowArrayStreamReader::try_new is technically unsound [arrow-rs]

Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey closed issue #10253: FFI_ArrowArrayStream + ArrowArrayStreamReader::try_new is technically unsound
URL: https://github.com/apache/arrow-rs/issues/10253


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org