tfussell / xlnt

:bar_chart: Cross-platform user-friendly xlsx library for C++11+
Other
1.47k stars 409 forks source link

Crash when formatting bigger range reference (more than 700 rows) #619

Open MichalDudkiewicz opened 2 years ago

MichalDudkiewicz commented 2 years ago

Hi

I've been using xlnt for saving my data to xlsx for quite a while without any problems. However recently when I was trying to save a little bit more data than usual and I encountered this:

double free or corruption (out)

Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

but sometimes it's:

free(): invalid pointer Signal: SIGABRT (Aborted)

This is the code, which is problematic:

  xlnt::alignment alignment;
  alignment.horizontal(xlnt::horizontal_alignment::center);
  alignment.vertical(xlnt::vertical_alignment::center);

  xlnt::worksheet ws = wb.create_sheet();

  int N = 720
  ws.range(xlnt::range_reference(1, 1, 5, N)).alignment(alignment);

Stack trace:

__GI_raise 0x00007f6a6167ce87
__GI_abort 0x00007f6a6167e7f1
__libc_message 0x00007f6a616c7837
malloc_printerr 0x00007f6a616ce8ba
_int_free 0x00007f6a616d5e4a
__GI___libc_free 0x00007f6a616d5e4a
__gnu_cxx::new_allocator::deallocate new_allocator.h:125
std::allocator_traits::deallocate alloc_traits.h:462
std::basic_string::_M_destroy basic_string.h:226
std::basic_string::_M_dispose basic_string.h:221
std::basic_string::~basic_string basic_string.h:647
xlnt::optional::clear optional.hpp:254
xlnt::optional::~optional optional.hpp:167
xlnt::font::~font font.hpp:40
__gnu_cxx::new_allocator::destroy<…> new_allocator.h:140
std::allocator_traits::destroy<…> alloc_traits.h:487
std::vector::_M_erase vector.tcc:159
std::vector::erase stl_vector.h:1180
xlnt::detail::stylesheet::garbage_collect<…> stylesheet.hpp:205
xlnt::detail::stylesheet::garbage_collect stylesheet.hpp:317
xlnt::detail::stylesheet::find_or_create stylesheet.hpp:404
xlnt::detail::stylesheet::find_or_create_with stylesheet.hpp:430
xlnt::format::alignment format.cpp:88
xlnt::cell::alignment cell.cpp:674
xlnt::range::<lambda>::operator()(xlnt::cell) const range.cpp:145
std::_Function_handler::_M_invoke(const std::_Any_data &, xlnt::cell &&) std_function.h:316
std::function::operator()(xlnt::cell) const std_function.h:706
xlnt::range::apply(std::function<…>) range.cpp:201
xlnt::range::alignment range.cpp:145
scheduler::OutputScheduleData::saveToXlsx output_schedule_data.cpp:399
main main.cpp:35
__libc_start_main 0x00007f6a6165fc87
_start 0x00005620f3aeb08a`

I also found out the N (numer of rows) value is problematic here. If it is below 700 everything is fine and the file is formatted as expected. When I comment the last line out it also doesn't crash. Any ideas what might be the reason? I am using v1.5.0 on Linux Ubuntu 18.04 compiling with GCC 7.5