openpnp / openpnp-capture

A cross platform video capture library with a focus on machine vision.
MIT License
129 stars 56 forks source link

Memory corruption #41

Closed raymanfx closed 4 years ago

raymanfx commented 4 years ago

Compiling with GLIBCXX_ASSERTIONS (basically cheap runtime array length checking) on Fedora 32 using GCC 10 reveals the following issue:

/usr/include/c++/10/bits/stl_vector.h:1042: std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = unsigned char; _Alloc = std::allocator<unsigned char>; std::vector<_Tp, _Alloc>::reference = unsigned char&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]: Assertion '__builtin_expect(__n < this->size(), true)' failed.
Aborted (core dumped)

To reproduce, insert add_definitions(-D_GLIBCXX_ASSERTIONS) in the main CMakeLists.txt and run the openpnp-capture-test binary, let it capture some frames and quit by pressing q. You should now see the assertion trace.

raymanfx commented 4 years ago

This is the GDB backtrace:

#0  0x00007ffff79f2a25 in raise () from /lib64/libc.so.6
#1  0x00007ffff79db895 in abort () from /lib64/libc.so.6
#2  0x0000000000406239 in std::__replacement_assert(char const*, int, char const*, char const*) ()
#3  0x0000000000406aa1 in std::vector<unsigned char, std::allocator<unsigned char> >::operator[](unsigned long) ()
#4  0x00007ffff7fb76ee in PlatformStream::threadSubmitBuffer(void*, unsigned long) ()
   from /home/chris/work/fedora/openpnp-capture/build/libopenpnp-capture.so.0.0.20
#5  0x00007ffff7fb6d6a in captureThreadFunctionAsync(PlatformStream*, int, unsigned long) ()
   from /home/chris/work/fedora/openpnp-capture/build/libopenpnp-capture.so.0.0.20
#6  0x00007ffff7fbaa59 in void std::__invoke_impl<void, void (*)(PlatformStream*, int, unsigned long), PlatformStream*, int, unsigned int>(std::__invoke_other, void (*&&)(PlatformStream*, int, unsigned long), PlatformStream*&&, int&&, unsigned int&&) () from /home/chris/work/fedora/openpnp-capture/build/libopenpnp-capture.so.0.0.20
#7  0x00007ffff7fba948 in std::__invoke_result<void (*)(PlatformStream*, int, unsigned long), PlatformStream*, int, unsigned int>::type std::__invoke<void (*)(PlatformStream*, int, unsigned long), PlatformStream*, int, unsigned int>(void (*&&)(PlatformStream*, int, unsigned long), PlatformStream*&&, int&&, unsigned int&&) ()
   from /home/chris/work/fedora/openpnp-capture/build/libopenpnp-capture.so.0.0.20
#8  0x00007ffff7fba83f in void std::thread::_Invoker<std::tuple<void (*)(PlatformStream*, int, unsigned long), PlatformStream*, int, unsigned int> >::_M_invoke<0ul, 1ul, 2ul, 3ul>(std::_Index_tuple<0ul, 1ul, 2ul, 3ul>) ()
   from /home/chris/work/fedora/openpnp-capture/build/libopenpnp-capture.so.0.0.20
#9  0x00007ffff7fba7c0 in std::thread::_Invoker<std::tuple<void (*)(PlatformStream*, int, unsigned long), PlatformStream*, int, unsigned int> >::operator()() () from /home/chris/work/fedora/openpnp-capture/build/libopenpnp-capture.so.0.0.20
#10 0x00007ffff7fba7a4 in std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (*)(PlatformStream*, int, unsigned long), PlatformStream*, int, unsigned int> > >::_M_run() ()
   from /home/chris/work/fedora/openpnp-capture/build/libopenpnp-capture.so.0.0.20
#11 0x00007ffff7ddda94 in execute_native_thread_routine () from /lib64/libstdc++.so.6
#12 0x00007ffff7b8b432 in start_thread () from /lib64/libpthread.so.0
#13 0x00007ffff7ab79d3 in clone () from /lib64/libc.so.6