sirfz / tesserocr

A Python wrapper for the tesseract-ocr API
MIT License
2.02k stars 255 forks source link

tesserocr module-level: avoid End() if Init() failed on TessBaseAPI #265

Closed bertsky closed 3 years ago

bertsky commented 3 years ago

This fixes a segfault when the Tesseract installation has no eng.traineddata or no tessdata dir, and no API object (besides the automatic module-level one) was instantiated before exit.

To reproduce the segfault:

python -c "import tesserocr"

(See here for further diagnosis.)

bertsky commented 3 years ago

The segfault is caused by a bug in Tesseract (see discussion. This PR is not needed (and also does not fix the bug, only works around it for one use case).

Ah, good to know. Did not see this.

But still – since we are on it: is End() really the correct thing to do if Init() resulted in a failure?

stweil commented 3 years ago

Maybe it's not necessary (or even not necessary at all in tesserocr as it is called in the destructor anyway), but it should be allowed to call it without causing any harm.