Repository navigation
Return None from GetChoiceIterator when not positioned on a word - #396
Merged
Merged
Conversation
sirfz#325) Creating a ChoiceIterator without a current word trips ASSERT_HOST in Tesseract, which aborts the whole Python process (e.g. when iterating RIL.SYMBOL on an image without text). Check for a word first and return None, as the docstring already documents for failures.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #325.
Problem
PyLTRResultIterator.GetChoiceIterator()constructs a TesseractChoiceIteratorunconditionally. When the result iterator is not on a word (for example an image without any text, or a non-text block), the constructor hitsASSERT_HOST(result_it.it_->word() != nullptr)and Tesseract aborts the entire Python process (exit 134), so it cannot be caught from Python:Fix
Check whether the iterator has a current word before constructing the
ChoiceIterator(GetUTF8Text(RIL_SYMBOL)returns NULL exactly whenword()is null) and returnNoneotherwise. The docstring already states "ReturnsNoneon failure"; the existingciter == NULLcheck could never trigger. The docstring now mentions this case.Tests
test_choice_iterator_without_word: blank image,GetChoiceIterator()returnsNone(before the fix this aborts the test process).test_choice_iterator: oneurotext.pngthe first symbol returns a choice iterator whose first choice isT.Verified locally (macOS arm64, Tesseract 5.5.3, Leptonica 1.87, Python 3.12): the new tests pass;
tests.test_signalsandtests.test_threadspass. Intests.test_api,test_detect_osaborts the interpreter andtest_initerrors (no legacy-engine traineddata in the Homebrew tessdata); both behave the same on unmodified master, so they are unrelated to this change. All othertest_apitests pass.Note: other iterator methods I probed at a word-less position (
WordFontAttributes,GetBestLSTMSymbolChoices, etc.) behave fine;GetBlamerDebugsegfaults there but is a debug-only API, so I left it out of scope.