OCR segmentation fault
Description of the bug
page.get_textpage_ocr segfaults for certain PDFs I am not allowed to share here. Tested on Linux and Mac.
Error message:
Python(99420,0x304424000) malloc: *** error for object 0xbe8b71dd402e3d31: pointer being freed was not allocated Python(99420,0x304424000) malloc: *** set a breakpoint in malloc_error_break to debug zsh: abort python3 main.py
How to reproduce the bug
pdf = fitz.open(...)
for page in pdf:
page.get_textpage_ocr(language='eng', full=False, tessdata=tessdata)
PyMuPDF version
1.24.2
Operating system
MacOS
Python version
3.8
We do need a reproducing file in order to deal with this post. So you must find a failing example that you can share.
Just a reminder: We will need to close this issue soon if we are unable to reproduce the problem with an example file.
Give me a second, I hope I will be able to generate an anonymized Version today. Thank you for your fast reply.
This here segfaults: 5.1.0 - Rücknahme - Protokoll - Schaden - FR.pdf
Sorry, still cannot reproduce. Here is my script:
import fitz
print(f"{fitz.version=}\n")
doc = fitz.open("test.pdf")
page = doc[0]
tessdata = fitz.get_tessdata()
print(f"{tessdata=}")
tp = page.get_textpage_ocr(full=False, dpi=300, tessdata=tessdata)
print(page.get_text(textpage=tp, sort=True))
Here is the output in Linux (don't have OSX). Works in Windows in the same way.
Also successfully tested full=True.
fitz.version=('1.24.2', '1.24.1', '20240417000001')
tessdata='/usr/share/tesseract-ocr/4.00/tessdata'
{{Anzahl_Schaden}}. {{Schaden}}
Pièces endommagées: {{Beschädigte Teile}}
Type de dommage: {{Schadensart}}
. >=
i
—
—
——
=
a
7
a
— =
-
\. =
:
‘S|
ae
|
ay] a"
‘ | )
;
| a
+
7
‘A \
A
™“
;
(1
>
. =
’
\
74
=
7
Nera
~
.
7 / (hfs
.
a
=)
/
wa, -— be <—
iv aq
Ee
f sa
‘
iY)
J )
z <i
—
ea
LHX
eee
X
eo)
ve Seed |
Si
¥ :
ES
.
4
~~ <{
4 —_ = = <<.
2x4
\”
|
f a @ sae be “ie Tote
=~
ay
7.4
\, =e
< oe
_
=
—S
se
wo...
cy ——
a
rr
Fig 1: {{Schaden}} {{Beschädigte Teile Detail}}
. >=
i
—
—
——
=
a
7
a
— =
-
\. =
:
‘S|
ae
|
ay] a"
‘ | )
;
| a
+
7
‘A \
A
™“
;
(1
>
. =
’
\
74
=
7
Nera
~
.
7 / (hfs
.
a
=)
/
wa, -— be <—
iv aq
Ee
f sa
‘
iY)
J )
z <i
—
ea
LHX
eee
X
eo)
ve Seed |
Si
¥ :
ES
.
4
~~ <{
4 —_ = = <<.
2x4
\”
|
f a @ sae be “ie Tote
=~
ay
7.4
\, =e
< oe
_
=
—S
se
wo...
cy ——
a
rr
Fig 2: {{Schaden}} {{Beschädigte Teile Detail}}
Carvolution AG - Neufeldweg 2 - 4913 Bannwil - carvolution.com
Then it's probably a macOS specific error. Thank you for checking.
I confused the error I got on Linux with a different problem and was able to resolve it, but the error on Mac persists.
Thanks for letting us know. I am closing this issue for now. Of course you can open another one once evidence suggests this.