Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: undefined behavior in schema ffi #582

Merged
merged 1 commit into from
Jul 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions arrow/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl FFI_ArrowSchema {
pub fn try_new(format: &str, children: Vec<FFI_ArrowSchema>) -> Result<Self> {
let mut this = Self::empty();

let mut children_ptr = children
let children_ptr = children
.into_iter()
.map(Box::new)
.map(Box::into_raw)
Expand All @@ -161,11 +161,14 @@ impl FFI_ArrowSchema {
this.format = CString::new(format).unwrap().into_raw();
this.release = Some(release_schema);
this.n_children = children_ptr.len() as i64;
this.children = children_ptr.as_mut_ptr();

let private_data = Box::new(SchemaPrivateData {
let mut private_data = Box::new(SchemaPrivateData {
children: children_ptr,
});

// intentionally set from private_data (see https://github.com/apache/arrow-rs/issues/580)
this.children = private_data.children.as_mut_ptr();

this.private_data = Box::into_raw(private_data) as *mut c_void;

Ok(this)
Expand Down