glassechidna / zxing-cpp

ZXing C++ Library
Apache License 2.0
598 stars 435 forks source link

GenericGF::multiply(int,int) BAD_ACCESS crash #12

Open TimZaman opened 9 years ago

TimZaman commented 9 years ago

Hi guys, i am doing some test on a huge barcode batch. It crashes often on multiply for some reason, see the trace below. Can't get my head around why, any ideas?

Crashed Thread: 125 QThread

Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00007ffe73094600

VM Regions Near 0x7ffe73094600:
 MALLOC_SMALL 00007ffcbf825000-00007ffcc0000000 [ 8044K] rw-/rwx SM=ZER 
--> 
 STACK GUARD 00007fff4ff8d000-00007fff5378d000 [ 56.0M] ---/rwx SM=NUL stack guard for thread 0

(...)

Thread 125 Crashed:: QThread
0 com.test 0x000000010bf6c4de zxing::GenericGF::multiply(int, int) + 62
1 com.test 0x000000010bf6d04f zxing::GenericGFPoly::evaluateAt(int) + 175
2 com.test 0x000000010bf6e80d zxing::ReedSolomonDecoder::decode(zxing::ArrayRef<int>, int) + 269
3 com.test 0x000000010bf7604e zxing::datamatrix::Decoder::correctErrors(zxing::ArrayRef<char>, int) + 414
4 com.test 0x000000010bf76448 zxing::datamatrix::Decoder::decode(zxing::Ref<zxing::BitMatrix>) + 648
5 com.test 0x000000010bf710e9 zxing::datamatrix::DataMatrixReader::decode(zxing::Ref<zxing::BinaryBitmap>, zxing::DecodeHints) + 137
6 com.test 0x000000010bf83374 zxing::MultiFormatReader::decodeInternal(zxing::Ref<zxing::BinaryBitmap>) + 148
7 com.test 0x000000010bf83553 zxing::MultiFormatReader::decode(zxing::Ref<zxing::BinaryBitmap>, zxing::DecodeHints) + 131
8 com.test 0x000000010beeac50 scanprocessor::decode_image_barcode(cv::Mat const?, std::__1::vector<int, std::__1::allocator<int> >) + 1680
9 com.test 0x000000010becc37b scanprocessor::getBarcodes(cv::Mat, double, std::__1::vector<int, std::__1::allocator<int> >, int) + 9739
10 com.test 0x000000010beb7ba7 scanprocessor::process(int, _CameraFile*, int, int, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) + 49575
11 com.test 0x000000010bcb0fce scanprocessor::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) + 1982
12 QtCore 0x000000010ed22743 QObject::event(QEvent*) + 755
13 QtWidgets 0x000000010df9e98b QApplicationPrivate::notify_helper(QObject*, QEvent*) + 251
14 QtWidgets 0x000000010dfa1c0c QApplication::notify(QObject*, QEvent*) + 7964
15 QtCore 0x000000010ecf7fab QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) + 987
16 QtCore 0x000000010ed57e38 postEventSourceDispatch(_GSource*, int (*)(void*), void*) + 24
17 libglib-2.0.0.dylib 0x00000001118d8728 g_main_context_dispatch + 282
18 libglib-2.0.0.dylib 0x00000001118d8a0b g_main_context_iterate + 404
19 libglib-2.0.0.dylib 0x00000001118d8a63 g_main_context_iteration + 55
20 QtCore 0x000000010ed57331 QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) + 97
21 QtCore 0x000000010ecf488d QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) + 381
22 QtCore 0x000000010eb34b15 QThread::exec() + 117
23 QtCore 0x000000010eb38679 QThreadPrivate::start(void*) + 313
24 libsystem_pthread.dylib 0x00007fff90484268 _pthread_body + 131
25 libsystem_pthread.dylib 0x00007fff904841e5 _pthread_start + 176
26 libsystem_pthread.dylib 0x00007fff9048241d thread_start + 13
Benjamin-Dobell commented 9 years ago

@TimZaman What's GenericGF's size? I didn't write this code (it's awful :wink:), however just looking at the code in initialize the algorithm will only work if size is a power of two.

TimZaman commented 9 years ago

Yep quite horrid, seems to work 999.999 out of a million though. The 1/1.000.000 part doesnt work, sadly. Any ideas how i approach to debug this? Love some guidance

SebGDev commented 9 years ago

@TimZaman: Just guessing, maybe the fix of the GenericGF memory leak could help: https://github.com/SebGDev/zxing-cpp/commit/03c3fa63d1be4df9402b3a6a1eaec8c872af5f71

Vidz1235 commented 9 years ago

Tried to composeanols to certain key words - straight to 2606?? Im new part of a community, just wanna c shanna... maybe twice???

Vidz1235 commented 9 years ago

Thankyou jesus! I hope this works$#3 On May 15, 2015 2:20 AM, "Sebastian" notifications@github.com wrote:

@TimZaman https://github.com/TimZaman: Just guessing, maybe the fix of the GenericGF memory leak could help: SebGDev@03c3fa6 https://github.com/SebGDev/zxing-cpp/commit/03c3fa63d1be4df9402b3a6a1eaec8c872af5f71

— Reply to this email directly or view it on GitHub https://github.com/glassechidna/zxing-cpp/issues/12#issuecomment-102314503 .

TimZaman commented 9 years ago

Nope doesn't work with the latest update. Keep jesus out of this, Vidz.

On Fri, May 15, 2015 at 10:27 AM, Vidz1235 notifications@github.com wrote:

Thankyou jesus! I hope this works$#3 On May 15, 2015 2:20 AM, "Sebastian" notifications@github.com wrote:

@TimZaman https://github.com/TimZaman: Just guessing, maybe the fix of the GenericGF memory leak could help: SebGDev@03c3fa6 < https://github.com/SebGDev/zxing-cpp/commit/03c3fa63d1be4df9402b3a6a1eaec8c872af5f71

— Reply to this email directly or view it on GitHub < https://github.com/glassechidna/zxing-cpp/issues/12#issuecomment-102314503

.

— Reply to this email directly or view it on GitHub https://github.com/glassechidna/zxing-cpp/issues/12#issuecomment-102315430 .

Benjamin-Dobell commented 9 years ago

Please try insert a conditional breakpoint in the constructor with condition:

(size & (size - 1)) != 0
TimZaman commented 9 years ago

Something like this, chief?

GenericGF::GenericGF(int primitive_, int size_, int b)
  : size(size_), primitive(primitive_), generatorBase(b), initialized(false) {
  if (size <= INITIALIZATION_THRESHOLD) {
    initialize();
  }

  if ((size & (size - 1)) != 0){
    throw IllegalArgumentException("(size & (size - 1)) != 0");
  }
}
Benjamin-Dobell commented 9 years ago

I meant using a debugger, but that should do the trick.

axxel commented 6 years ago

@TimZaman If you see any chance of resurrecting the datamatrix image content that caused this issue, I'd be very interested in getting my hands on that for testing. I recently removed a ton of temporary memory allocations that were ported from Java to this new c++ port in the GF-related code and also 'dehorrified' it a little ;).