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

[C++] PrimitiveArrays cause segmentation faults in PrettyPrinter #45301

Open
sjperkins opened this issue Jan 19, 2025 · 0 comments
Open

[C++] PrimitiveArrays cause segmentation faults in PrettyPrinter #45301

sjperkins opened this issue Jan 19, 2025 · 0 comments

Comments

@sjperkins
Copy link
Contributor

Describe the bug, including details regarding any error messages, version, and platform.

Arrays created with the PrimitiveArray(datatype, length, buffer) constructor aren't usable with PrettyPrinter. A workaround is to use the lower level arrow::MakeArray API.

This is likely low-priority or perhaps not an issue as the constructor isn't documented as part of the public API.

Here's a reproducer:

#include <iostream>
#include <memory>

#include <arrow/api.h>

using ::arrow::ArrayData;
using ::arrow::Buffer;
using ::arrow::PrimitiveArray;

const std::int64_t N = 1000;

int main(int argc, char * argv[]) {
  auto buffer = std::shared_ptr<arrow::Buffer>(arrow::AllocateBuffer(N * sizeof(double)).ValueOrDie());
  auto span = buffer->mutable_span_as<double>();
  for(std::size_t i=0; i<N; ++i) span[i] = double(i);

  if (true) {
    auto a = std::make_shared<PrimitiveArray>(arrow::float64(), N, buffer);
    // This is a valid array
    assert(a->ValidateFull().ok());
    // bad_cast from PrimiveArray to NumericArray<arrow::Double>
    // core dumps
    std::cout << a->ToString() << std::endl;
  }

  if (true) {
    auto buffers = std::vector<std::shared_ptr<Buffer>>{nullptr, buffer};
    auto data = std::make_shared<ArrayData>(arrow::float64(), N, std::move(buffers));
    auto a = arrow::MakeArray(data);
    // This is a valid array
    assert(a->ValidateFull().ok());
    std::cout << a->ToString() << std::endl;
  }

And an example of the backtrace it creates:

(gdb) bt
#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=<optimized out>)
    at ./nptl/pthread_kill.c:44
#1  __pthread_kill_internal (signo=6, threadid=<optimized out>)
    at ./nptl/pthread_kill.c:78
#2  __GI___pthread_kill (threadid=<optimized out>, signo=signo@entry=6)
    at ./nptl/pthread_kill.c:89
#3  0x0000790c64c4526e in __GI_raise (sig=sig@entry=6)
    at ../sysdeps/posix/raise.c:26
#4  0x0000790c64c288ff in __GI_abort () at ./stdlib/abort.c:79
#5  0x0000790c650d5fae in __gnu_cxx::__verbose_terminate_handler ()
    at ../../../../libstdc++-v3/libsupc++/vterminate.cc:95
#6  0x0000790c650d44f2 in __cxxabiv1::__terminate (handler=<optimized out>)
    at ../../../../libstdc++-v3/libsupc++/eh_terminate.cc:48
#7  0x0000790c650ce2f3 in std::terminate ()
    at ../../../../libstdc++-v3/libsupc++/eh_terminate.cc:58
#8  0x0000790c650d4712 in __cxxabiv1::__cxa_throw (obj=0x5e37424e6d60, 
    tinfo=0x790c651ef078 <typeinfo for std::bad_cast>, 
    dest=0x790c650d30fe <std::bad_cast::~bad_cast()>)
    at ../../../../libstdc++-v3/libsupc++/eh_throw.cc:98
#9  0x0000790c650ce248 in __cxxabiv1::__cxa_bad_cast ()
    at ../../../../libstdc++-v3/libsupc++/eh_aux_runtime.cc:34
#10 0x0000790c65746ef9 in arrow::internal::checked_cast<arrow::NumericArray<arrow::DoubleType> const&, arrow::Array const&> (value=...)
--Type <RET> for more, q to quit, c to continue without paging--
    at /home/simon/code/arrow/cpp/src/arrow/util/checked_cast.h:38
#11 0x0000790c65743484 in arrow::VisitArrayInline<arrow::(anonymous namespace)::ArrayPrinter> (array=..., visitor=0x7ffd5fd803d0)
    at /home/simon/code/arrow/cpp/src/arrow/visit_array_inline.h:55
#12 0x0000790c6573e6ea in arrow::(anonymous namespace)::ArrayPrinter::Print (this=0x7ffd5fd803d0, array=...) at /home/simon/code/arrow/cpp/src/arrow/pretty_print.cc:401
#13 0x0000790c6573ebe1 in arrow::PrettyPrint (arr=..., indent=0, sink=0x7ffd5fd80580) at /home/simon/code/arrow/cpp/src/arrow/pretty_print.cc:430
#14 0x0000790c65a9cf09 in arrow::Array::ToString[abi:cxx11]() const (this=0x5e37424e6a90) at /home/simon/code/arrow/cpp/src/arrow/array/array_base.cc:301
#15 0x00005e370f5cb456 in main ()

Component(s)

C++

@sjperkins sjperkins changed the title PrimitiveArrays segfault PrettyPrinter [C++] PrimitiveArrays segfault PrettyPrinter Jan 19, 2025
@sjperkins sjperkins changed the title [C++] PrimitiveArrays segfault PrettyPrinter [C++] PrimitiveArrays cause segmentation faults PrettyPrinter Jan 19, 2025
@sjperkins sjperkins changed the title [C++] PrimitiveArrays cause segmentation faults PrettyPrinter [C++] PrimitiveArrays cause segmentation faults in PrettyPrinter Jan 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant