fix(ffi): make FFI struct fields private to close Drop soundness hole#10431
Open
bit2swaz wants to merge 2 commits into
Open
fix(ffi): make FFI struct fields private to close Drop soundness hole#10431bit2swaz wants to merge 2 commits into
bit2swaz wants to merge 2 commits into
Conversation
…fields private to close Drop soundness hole
bit2swaz
marked this pull request as ready for review
July 24, 2026 18:55
Contributor
|
I believe you fixed the MIRI error on #10433 Merging up to retrigger and get a clean run |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Closes #10429.
Rationale for this change
FFI_ArrowArray,FFI_ArrowSchema, andFFI_ArrowArrayStreamall have public fields, including thereleasefn pointer that each struct'sDropimpl calls. Safe Rust can construct any of them with a garbagereleasecallback and trigger UB on drop, with nounsafeblock anywhere in sight.Drop::dropcan't beunsafe fn, so there's no way to put the safety obligation on the caller at the drop site. The only fix is making the fields private, so garbage instances can't be constructed from safe code in the first place.This came up in #10253. @Jefffrey pointed out that the Drop impl has the same problem and that
FFI_ArrowArrayis prone to it too, so the fix needs to cover all three structs.What changes are included in this PR?
Stripped
pubfrom all fields onFFI_ArrowArray(arrow-data),FFI_ArrowSchema(arrow-schema), andFFI_ArrowArrayStream(arrow-array). No new logic, no new public API.One test in
arrow-data/src/ffi.rswas accessingn_buffersandprivate_datadirectly as a child module. Replaced withffi_array.num_buffers(), which is the existing public getter for the same information.#[repr(C)]layout is determined by field types and order, not visibility, so the ABI is unchanged. External C producers fill these structs as raw memory and hand a pointer to Rust viafrom_raw, which is alreadyunsafe.Are these changes tested?
Yes. All existing tests pass. The soundness hole is now a compile error: constructing any of the three structs with struct literal syntax from outside the defining module fails with
fields ... are private.Are there any user-facing changes?
Breaking change for any downstream Rust code constructing these structs with struct literal syntax (e.g.
FFI_ArrowArray { release: Some(f), ... }). That pattern was only valid in safe code for the struct fields that had no raw pointer invariants, but it was the exact vector for the soundness hole, so closing it is the point. Code using the public constructors (new,empty,from_raw) is unaffected.