Skip to content

Commit

Permalink
Fix undefined behavor in GenericStringArray::from_iter_values
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb committed Jan 8, 2022
1 parent 719096b commit db22383
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion arrow/src/array/array_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,15 @@ impl<OffsetSize: StringOffsetSizeTrait> GenericStringArray<OffsetSize> {
offsets.push(length_so_far);
values.extend_from_slice(s.as_bytes());
}

// iterator size hint may not be correct so compute the actual number of offsets
let actual_len = match offsets.len() {
0 => 0,
len => (len / std::mem::size_of::<OffsetSize>()) - 1
};

let array_data = ArrayData::builder(OffsetSize::DATA_TYPE)
.len(data_len)
.len(actual_len)
.add_buffer(offsets.into())
.add_buffer(values.into());
let array_data = unsafe { array_data.build_unchecked() };
Expand Down

0 comments on commit db22383

Please sign in to comment.