-
Notifications
You must be signed in to change notification settings - Fork 4.1k
[Rust] Possibly incorrect index check assertion in StringArray and BinaryArray #23818
Copy link
Copy link
Closed
Description
The following code tries to build a list array based on an underlying string array and panics on master (commit acfcdee)
#[test]
fn nested_string_array() {
let strarray = StringArray::from(vec!["foo", "bar", "foobar"]);
let nestedData = ArrayData::builder(DataType::List(Box::new(DataType::Utf8)))
.len(2)
.add_buffer(Buffer::from(&[0, 2, 3].to_byte_slice()))
.add_child_data(ArrayData::builder(DataType::Utf8)
.len(strarray.len())
.add_buffer(strarray.value_offsets())
.add_buffer(strarray.value_data())
.build())
.build();
let nestedArray = ListArray::from(nestedData);
dbg!(nestedArray);
}My guess is that the index check in StringArray.value is incorrect, instead of
pub fn value(&self, i: usize) -> &str {
assert!(
i + self.offset() < self.data.len(),
"StringArray out of bounds access"
);it should probably compare i without adding the offset. The same check is also done in BinaryArray. Changing this results in the expected output of
[arrow/src/array/array.rs:2460] nestedArray = ListArray
[
StringArray
[
"foo",
"bar",
],
StringArray
[
"foobar",
],
]
Reporter: Jörn Horstmann / @jhorstmann
Assignee: Paddy Horan / @paddyhoran
PRs and other links:
Note: This issue was originally created as ARROW-7559. Please see the migration documentation for further details.
Reactions are currently unavailable