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

Segfault with new image and rus+mrz in recent main #4361

Open
marcreichman-pfi opened this issue Nov 25, 2024 · 17 comments
Open

Segfault with new image and rus+mrz in recent main #4361

marcreichman-pfi opened this issue Nov 25, 2024 · 17 comments

Comments

@marcreichman-pfi
Copy link

Current Behavior

With the attached image, and recent main (9f17a3fd) I receive a segfault in Release (SIGILL in Debug) with the mrz and rus langages. Both are fast. Rus is official and mrz is available here

Release:

<snip>/tesseract-fork/cmake-build-release/bin/tesseract <snip>/62553353F7495226759F9644269AA485-sample_000101.jpg - --tessdata-dir <snip>/tessdata/ -l mrz+rus
Estimating resolution as 971

Process finished with exit code 139 (interrupted by signal 11:SIGSEGV)

Debug:

Estimating resolution as 971
ELIST2_ITERATOR::add_before_stay_put:Error:Attempting to add an element with non nullptr links, to a list

Process finished with exit code 132 (interrupted by signal 4:SIGILL)

new-segfault-20241125

Expected Behavior

No segfault.

Suggested Fix

No response

tesseract -v

tesseract 5.5.0-26-g9f17a
 leptonica-1.82.0
  libgif 5.1.9 : libjpeg 8d (libjpeg-turbo 2.1.1) : libpng 1.6.37 : libtiff 4.3.0 : zlib 1.2.11 : libwebp 1.2.2 : libopenjp2 2.4.0
 Found AVX
 Found SSE4.1
 Found OpenMP 201511

Operating System

Ubuntu 22.04 Jammy

Other Operating System

This is running via WSL but it does not appear related to the issue.

uname -a

Linux hostname 5.10.16.3-microsoft-standard-WSL2 #1 SMP Fri Apr 2 22:23:49 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Compiler

GCC 11.4

CPU

Intel(R) Core(TM) i7-3720QM CPU @ 2.60GHz

Virtualization / Containers

No explicit VM except for WSL2

Other Information

This works in 5.5.0 tag

@marcreichman-pfi marcreichman-pfi changed the title Segfault with new image and rus+mrz in latest main Segfault with new image and rus+mrz in recent main Nov 25, 2024
@egorpugin
Copy link
Contributor

egorpugin commented Nov 25, 2024

Can you run your command under gdb and post stack trace? (debug tess binary)

gdb tesseract
set args *your args to tesseract*
r

* wait for the crash *

bt

@marcreichman-pfi
Copy link
Author

@egorpugin This is with a debug build, hence the SIGILL instead of SIGSEGV:

(gdb) set args ~/dev/testimages/new-segfault-20241125.jpg - --tessdata-dir <snip>/tessdata/ -l mrz+rus
(gdb) r
Starting program: /root/dev/tesseract/build-debug/bin/tesseract ~/dev/testimages/new-segfault-20241125.jpg - --tessdata-dir <snip>/tessdata/ -l mrz+rus
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Estimating resolution as 971
[New Thread 0x7ffff73c6640 (LWP 1893)]
[New Thread 0x7ffff6bc5640 (LWP 1894)]
[New Thread 0x7ffff63c4640 (LWP 1895)]
ELIST2_ITERATOR::add_before_stay_put:Error:Attempting to add an element with non nullptr links, to a list

Thread 1 "tesseract" received signal SIGILL, Illegal instruction.
tesseract::ERRCODE::error (this=this@entry=0x5555558a1308 <tesseract::STILL_LINKED>, caller=caller@entry=0x5555557f8f00 "ELIST2_ITERATOR::add_before_stay_put", action=action@entry=tesseract::ABORT, format=format@entry=0x0) at /root/dev/tesseract/src/ccutil/errcode.cpp:78
78            __builtin_trap();
(gdb) bt
#0  tesseract::ERRCODE::error (this=this@entry=0x5555558a1308 <tesseract::STILL_LINKED>, caller=caller@entry=0x5555557f8f00 "ELIST2_ITERATOR::add_before_stay_put",
    action=action@entry=tesseract::ABORT, format=format@entry=0x0) at /root/dev/tesseract/src/ccutil/errcode.cpp:78
#1  0x000055555558a98d in tesseract::ERRCODE::error (action=tesseract::ABORT, caller=0x5555557f8f00 "ELIST2_ITERATOR::add_before_stay_put", this=0x5555558a1308 <tesseract::STILL_LINKED>)
    at /root/dev/tesseract/src/ccutil/errcode.h:47
#2  tesseract::IntrusiveList<tesseract::WERD>::Iterator::add_before_stay_put (new_element=0x555556132100, this=0x7fffffffd8f0) at /root/dev/tesseract/src/ccutil/elst2.h:387
#3  tesseract::PAGE_RES_IT::ReplaceCurrentWord (this=this@entry=0x7fffffffdc10, words=words@entry=0x7fffffffdaa0) at /root/dev/tesseract/src/ccstruct/pageres.cpp:1469
#4  0x0000555555612f42 in tesseract::Tesseract::classify_word_and_language (this=this@entry=0x7ffff73c7010, pass_n=pass_n@entry=1, pr_it=pr_it@entry=0x7fffffffdc10,
    word_data=word_data@entry=0x555556ba5cd0) at /root/dev/tesseract/src/ccmain/control.cpp:1367
#5  0x000055555561a01f in tesseract::Tesseract::RecogAllWordsPassN (this=this@entry=0x7ffff73c7010, pass_n=pass_n@entry=1, monitor=monitor@entry=0x0, pr_it=pr_it@entry=0x7fffffffdc10,
    words=words@entry=0x7fffffffdbf0) at /root/dev/tesseract/src/ccmain/control.cpp:255
#6  0x000055555561a456 in tesseract::Tesseract::recog_all_words (this=0x7ffff73c7010, page_res=0x555556bb7160, monitor=monitor@entry=0x0, target_word_box=target_word_box@entry=0x0,
    word_config=word_config@entry=0x0, dopasses=dopasses@entry=0) at /root/dev/tesseract/src/ccmain/control.cpp:345
#7  0x00005555555d5553 in tesseract::TessBaseAPI::Recognize (this=this@entry=0x7fffffffe2e0, monitor=monitor@entry=0x0) at /root/dev/tesseract/src/api/baseapi.cpp:833
#8  0x00005555555d57e3 in tesseract::TessBaseAPI::ProcessPage (this=this@entry=0x7fffffffe2e0, pix=0x5555558d6020, page_index=page_index@entry=0,
    filename=filename@entry=0x7fffffffe783 "/root/dev/testimages/new-segfault-20241125.jpg", retry_config=retry_config@entry=0x0, timeout_millisec=timeout_millisec@entry=0,
    renderer=0x5555558d2740) at /root/dev/tesseract/src/api/baseapi.cpp:1218
#9  0x00005555555d68e4 in tesseract::TessBaseAPI::ProcessPagesInternal (this=this@entry=0x7fffffffe2e0, filename=0x7fffffffe783 "/root/dev/testimages/new-segfault-20241125.jpg",
    retry_config=retry_config@entry=0x0, timeout_millisec=timeout_millisec@entry=0, renderer=0x5555558d2740) at /root/dev/tesseract/src/api/baseapi.cpp:1181
#10 0x00005555555d69ea in tesseract::TessBaseAPI::ProcessPages (this=this@entry=0x7fffffffe2e0, filename=<optimized out>, retry_config=retry_config@entry=0x0,
    timeout_millisec=timeout_millisec@entry=0, renderer=<optimized out>) at /root/dev/tesseract/src/api/baseapi.cpp:998
#11 0x000055555556d6c3 in main (argc=<optimized out>, argv=<optimized out>) at /usr/include/c++/11/bits/unique_ptr.h:173
(gdb)

@egorpugin
Copy link
Contributor

Now please download this file
https://github.com/tesseract-ocr/tesseract/blob/5c78037bd3d79dbb71bdccf6333a8d94b530fd19/src/ccutil/helpers.h
replace src/ccutil/helpers.h with it
rebuild debug build and try again.

@marcreichman-pfi
Copy link
Author

@egorpugin This one works fine now.

On a hunch I ran the images from #4148, and those now fail again.

I am sure from your comments you understand, the random stuff is masking the various failures that may actually be happening under the hood.

@egorpugin
Copy link
Contributor

Yes, that is what I'm testing.

@egorpugin
Copy link
Contributor

It is better to keep that bunch of tickets open until the real issue(s) are fixed.

@amitdo
Copy link
Collaborator

amitdo commented Nov 25, 2024

Try to add a black frame to the image.

convert in.png -bordercolor Black -border 10x10 in-black-bprder.png

@marcreichman-pfi
Copy link
Author

Hi @amitdo, I am aware that subtle changes to the images usually make things work. We've had a series of images while using high throughput through many videos and other images. The segfaults and aborts are popping up from time to time which is why we're filing the tickets.

Thanks!

@amitdo
Copy link
Collaborator

amitdo commented Nov 25, 2024

Please try it and tell me if after adding the black frame you still get a segfault.

@marcreichman-pfi
Copy link
Author

Hi @amitdo

With the border it did not create a segfault. I also tried some others.

convert in.jpg -bordercolor Black -border 10x10 in-black-border.jpg <- no crash
convert in.jpg -bordercolor Black -border 10x10 in-black-border.png <- no crash
convert in.jpg in-copy.jpg <- no crash
convert in.jpg in-copy.png <- crash

All of this makes sense based on things I've seen testing all these tickets.

@amitdo
Copy link
Collaborator

amitdo commented Nov 26, 2024

Like the issues in boxClipToRectangle , Tesseract does not like images where pixels from the foreground touch the image frame.

@stweil
Copy link
Contributor

stweil commented Nov 27, 2024

@marcreichman-pfi, could you please give #4362 (comment) a try? Do you still get crashs with this code change? And similar important: does it change the OCR results?

@marcreichman-pfi
Copy link
Author

Hi @stweil - will try it Monday. Thanks!

@marcreichman-pfi
Copy link
Author

Hi @stweil,

I made the change you suggested locally, and ran through all of my local test files from various tickets. It did not fix the SEGV, but it did fix the abort in #4362. Outputs are slightly modified in most cases but not dramatically so.

Full run of tests with c1bb752e:

/home/snip/dev/tesseract-fork/cmake-build-release/bin/tesseract /home/snip/Downloads/sample_002781.jpg - --tessdata-dir /home/snip/dev/snip/tessdata/ -l mrz+chi_sim_vert
Estimating resolution as 273
LIIZIGEIL

/home/snip/dev/tesseract-fork/cmake-build-release/bin/tesseract /home/snip/Downloads/sample_002781-fullframe.png - --tessdata-dir /home/snip/dev/snip/tessdata/ -l mrz+chi_sim_vert
Estimating resolution as 260
8887753773

/home/snip/dev/tesseract-fork/cmake-build-release/bin/tesseract /home/snip/Downloads/cpac.jpg - --tessdata-dir /home/snip/dev/snip/tessdata/ -l ara_fast+ocrb_int
Estimating resolution as 303
C

/home/snip/dev/tesseract-fork/cmake-build-release/bin/tesseract /home/snip/Downloads/4146-1.jpg - --tessdata-dir /home/snip/dev/snip/tessdata/ -l chi_sim+mrz
Estimating resolution as 548
Detected 110 diacritics
TTTEL

C1UI 出 B

J H <

中| 由

 <1 G

IISUIB

B

UHHT

/home/snip/dev/tesseract-fork/cmake-build-release/bin/tesseract /home/snip/Downloads/4146-2.jpg - --tessdata-dir /home/snip/dev/snip/tessdata/ -l eng+ara_fast+ocrb_int
Estimating resolution as 975
: | mine |

ELLATORDF 2 7
NALD MAD
26 | # y 31 oe) E

١0 BELLA

/home/snip/dev/tesseract-fork/cmake-build-release/bin/tesseract /home/snip/Downloads/62553353F7495226759F9644269AA485-sample_000101.jpg - --tessdata-dir /home/snip/dev/snip/tessdata/ -l mrz+rus
Estimating resolution as 971

Process finished with exit code 139 (interrupted by signal 11:SIGSEGV)

/home/snip/dev/tesseract-fork/cmake-build-release/bin/tesseract /home/snip/Downloads/ACCDEE72E33B2C425E597A4411009466.jpg - --tessdata-dir /home/snip/dev/snip/tessdata -l eng+chi_tra
Estimating resolution as 261
Detected 12 diacritics
!w_it.cycled_list():Error:Assert failed:in file /home/snip/dev/tesseract-fork/src/ccstruct/pageres.cpp, line 1502

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

/home/snip/dev/tesseract-fork/cmake-build-release/bin/tesseract /home/snip/Downloads/cpac.jpg - --tessdata-dir /home/snip/dev/snip/tessdata/ -l ara_fast+chi_tra
Estimating resolution as 303
جا ا-00

Full run of tests with the suggested change:

/home/snip/dev/tesseract-fork/cmake-build-release/bin/tesseract /home/snip/Downloads/sample_002781.jpg - --tessdata-dir /home/snip/dev/snip/tessdata/ -l mrz+chi_sim_vert
Estimating resolution as 273
LIZIGEIE

/home/snip/dev/tesseract-fork/cmake-build-release/bin/tesseract /home/snip/Downloads/sample_002781-fullframe.png - --tessdata-dir /home/snip/dev/snip/tessdata/ -l mrz+chi_sim_vert
Estimating resolution as 260
LIIZIEEICJ

/home/snip/dev/tesseract-fork/cmake-build-release/bin/tesseract /home/snip/Downloads/cpac.jpg - --tessdata-dir /home/snip/dev/snip/tessdata/ -l ara_fast+ocrb_int
Estimating resolution as 303

/home/snip/dev/tesseract-fork/cmake-build-release/bin/tesseract /home/snip/Downloads/4146-1.jpg - --tessdata-dir /home/snip/dev/snip/tessdata/ -l chi_sim+mrz
Estimating resolution as 548
Detected 110 diacritics
TTTBE

中 W B

J M V

用 由

 <1 R

II

T

LHHT

/home/snip/dev/tesseract-fork/cmake-build-release/bin/tesseract /home/snip/Downloads/4146-2.jpg - --tessdata-dir /home/snip/dev/snip/tessdata/ -l eng+ara_fast+ocrb_int
Estimating resolution as 975
: | mien |

ELLATORDF = =
NALD MAD
26 | * y 31١ wee

, BELLA

/home/snip/dev/tesseract-fork/cmake-build-release/bin/tesseract /home/snip/Downloads/62553353F7495226759F9644269AA485-sample_000101.jpg - --tessdata-dir /home/snip/dev/snip/tessdata/ -l mrz+rus
Estimating resolution as 971

Process finished with exit code 139 (interrupted by signal 11:SIGSEGV)

/home/snip/dev/tesseract-fork/cmake-build-release/bin/tesseract /home/snip/Downloads/ACCDEE72E33B2C425E597A4411009466.jpg - --tessdata-dir /home/snip/dev/snip/tessdata -l eng+chi_tra
Estimating resolution as 261
Detected 12 diacritics
(i eet |
=

一
al te

———,

cane,

* Eee a


/home/snip/dev/tesseract-fork/cmake-build-release/bin/tesseract /home/snip/Downloads/cpac.jpg - --tessdata-dir /home/snip/dev/snip/tessdata/ -l ara_fast+chi_tra
Estimating resolution as 303
ج06 ا


I ran the file from #4362 with my previous workaround for the sigabrt (changing the assert to an if) - this file is ACCDEE72E33B2C425E597A4411009466.jpg in the previous two text blocks. The output is similar but not exactly the same, from my workaround case, to your workaround case.

Your workaround:

/home/snip/dev/tesseract-fork/cmake-build-release/bin/tesseract /home/snip/Downloads/ACCDEE72E33B2C425E597A4411009466.jpg - --tessdata-dir /home/snip/dev/snip/tessdata -l eng+chi_tra
Estimating resolution as 261
Detected 12 diacritics
(i eet |
=

一
al te

———,

cane,

* Eee a

My workaround:

/home/snip/dev/tesseract-fork/cmake-build-release/bin/tesseract /home/snip/Downloads/ACCDEE72E33B2C425E597A4411009466.jpg - --tessdata-dir /home/snip/dev/snip/tessdata -l eng+chi_tra
Estimating resolution as 261
Detected 12 diacritics
|
=

一
al te

———,

eae,

eel a

In the end, I'm not sure which workaround is "better" but they both succeed where the plain c1bb752e does the SIGABRT for #4362. None of the three remove this SEGV, but to reiterate this SEGV did not happen on the released 5.5.0, which had other issues of course.

Thanks for your continued attention!

@egorpugin
Copy link
Contributor

definitely the issue should be investigated with this change

-      line[i] = IntCastRounded(randomizer->SignedRand(INT8_MAX));
+      line[i] = 0;

@marcreichman-pfi
Copy link
Author

Hi @egorpugin - just tried it in this previous comment

Thanks!

@egorpugin
Copy link
Contributor

Yes, I mean we should track down the issue using 0 value instead of any randoms.

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

4 participants