Skip to content

Panic (offset + length) <= self.len() in make_array on sliced struct in arrow 55 #7750

Closed

Description

@rluvaton

Describe the bug
Panic when trying to call make_array on sliced struct, this does not fail on tag 54.3.0 and it does fail on 55.0.0, 55.1.0 and master

To Reproduce
The following test panic:

#[test]
fn debug() {
    let strings: ArrayRef = Arc::new(StringArray::from(vec![
        Some("joe"),
        None,
        None,
        Some("mark"),
        Some("doe"),
    ]));
    let ints: ArrayRef = Arc::new(Int32Array::from(vec![
        Some(1),
        Some(2),
        Some(3),
        Some(4),
        Some(5),
    ]));

    let array = StructArray::try_from(vec![("f1", strings.clone()), ("f2", ints.clone())])
      .unwrap()
      .into_data()
      .slice(1, 3);

    let arrays: ArrayRef = arrow::array::make_array(array.clone());
}

With:

assertion failed: (offset + length) <= self.len()
thread 'debug' panicked at arrow-data/src/data.rs:550:9:
assertion failed: (offset + length) <= self.len()
stack backtrace:
   0: __rustc::rust_begin_unwind
             at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/std/src/panicking.rs:697:5
   1: core::panicking::panic_fmt
             at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/core/src/panicking.rs:75:14
   2: core::panicking::panic
             at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/core/src/panicking.rs:145:5
   3: arrow_data::data::ArrayData::slice
             at /Users/rluvaton/dev/open-source/apache/arrow-rs/arrow-data/src/data.rs:550:9
   4: <arrow_array::array::struct_array::StructArray as core::convert::From<arrow_data::data::ArrayData>>::from::{{closure}}
             at /Users/rluvaton/dev/open-source/apache/arrow-rs/arrow-array/src/array/struct_array.rs:358:32
   5: core::iter::adapters::map::map_fold::{{closure}}
             at /Users/rluvaton/.rustup/toolchains/1.87.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/iter/adapters/map.rs:88:28
   6: <core::slice::iter::Iter<T> as core::iter::traits::iterator::Iterator>::fold
             at /Users/rluvaton/.rustup/toolchains/1.87.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/slice/iter/macros.rs:255:27
   7: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
             at /Users/rluvaton/.rustup/toolchains/1.87.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/iter/adapters/map.rs:128:9
   8: core::iter::traits::iterator::Iterator::for_each
             at /Users/rluvaton/.rustup/toolchains/1.87.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/iter/traits/iterator.rs:800:9
   9: alloc::vec::Vec<T,A>::extend_trusted
             at /Users/rluvaton/.rustup/toolchains/1.87.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/vec/mod.rs:3579:17
  10: <alloc::vec::Vec<T,A> as alloc::vec::spec_extend::SpecExtend<T,I>>::spec_extend
             at /Users/rluvaton/.rustup/toolchains/1.87.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/vec/spec_extend.rs:29:9
  11: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter_nested::SpecFromIterNested<T,I>>::from_iter
             at /Users/rluvaton/.rustup/toolchains/1.87.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/vec/spec_from_iter_nested.rs:62:9
  12: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
             at /Users/rluvaton/.rustup/toolchains/1.87.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/vec/spec_from_iter.rs:34:9
  13: <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter
             at /Users/rluvaton/.rustup/toolchains/1.87.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/vec/mod.rs:3438:9
  14: core::iter::traits::iterator::Iterator::collect
             at /Users/rluvaton/.rustup/toolchains/1.87.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/iter/traits/iterator.rs:1985:9
  15: <arrow_array::array::struct_array::StructArray as core::convert::From<arrow_data::data::ArrayData>>::from
             at /Users/rluvaton/dev/open-source/apache/arrow-rs/arrow-array/src/array/struct_array.rs:353:22
  16: arrow_array::array::make_array
             at /Users/rluvaton/dev/open-source/apache/arrow-rs/arrow-array/src/array/mod.rs:814:41
  17: array_transform::debug
             at ./tests/array_transform.rs:1178:28
  18: array_transform::debug::{{closure}}
             at ./tests/array_transform.rs:1157:11
  19: core::ops::function::FnOnce::call_once
             at /Users/rluvaton/.rustup/toolchains/1.87.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
  20: core::ops::function::FnOnce::call_once
             at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/core/src/ops/function.rs:250:5

Expected behavior
Should not panic

Additional context
Cc @westonpace, the following PR introduce the regression:

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions