fix: guard FFI schema metadata on empty schema#10289
Open
cyphercodes wants to merge 1 commit into
Open
Conversation
alamb
reviewed
Jul 10, 2026
| I: IntoIterator<Item = (S, S)>, | ||
| S: AsRef<str>, | ||
| { | ||
| if self.private_data.is_null() { |
Contributor
There was a problem hiding this comment.
~I don't understand this -- the code below sets private data ~
update -- I see now
unsafe {
let mut private_data = Box::from_raw(self.private_data as *mut SchemaPrivateData);
private_data.metadata = new_metadata;
self.private_data = Box::into_raw(private_data) as *mut c_void;
}
alamb
reviewed
Jul 10, 2026
alamb
left a comment
Contributor
There was a problem hiding this comment.
FFI_ArrowSchema::empty() leaves private_data null. Calling the safe with_metadata builder on that value previously reached Box::from_raw(self.private_data as *mut SchemaPrivateData), which is undefined behavior for a null pointer.
Perhaps it would be more future proof to just set private_data for the result of FFI_ArrowSchema::empty()?
It seems like it is not unreasonable to set metadata on an empty schema, and I worry that other existing (or newly added) code paths will assume private_data is non null
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?
FFI_ArrowSchema::with_metadatawhen used with empty schema #10286.Rationale for this change
FFI_ArrowSchema::empty()leavesprivate_datanull. Calling the safewith_metadatabuilder on that value previously reachedBox::from_raw(self.private_data as *mut SchemaPrivateData), which is undefined behavior for a null pointer.What changes are included in this PR?
CDataInterfaceerror fromFFI_ArrowSchema::with_metadatawhenprivate_datais null.with_metadataonFFI_ArrowSchema::empty().Are these changes tested?
Yes:
cargo fmt -p arrow-schema -- --checkcargo test -p arrow-schema --features ffi test_set_metadata_on_empty_schema_errors -- --nocapturecargo test -p arrow-schema --features ffi test_set_field_metadata -- --nocapturecargo test -p arrow-schema --features ffi ffi::tests::test_schema -- --nocapturecargo test -p arrow-schema --features fficargo clippy -p arrow-schema --features ffi --all-targets -- -D warningsAre there any user-facing changes?
No API shape changes. Calling
with_metadataon an empty/released FFI schema now returns an error instead of invoking undefined behavior.AI assistance
AI assistance was used to prepare this small patch; I reviewed the change and verified it with the commands listed above.