Skip to content

Conversation

@stweil
Copy link
Member

@stweil stweil commented May 13, 2024

No description provided.

tessdata_prefix = TESSDATA_PREFIX;
datadir = tessdata_prefix;
datadir += "/tessdata/";
// in the binary, so it might be shorter. Recalculate its length.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since std::string is initialized from "const char*", I wonder how it can be shorter?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The length is calculated at compile time and not updated at runtime if the const char * was patched.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have a locally built tesseract installed in /usr/local/bin (= with prefix /usr/local), you can patch the binary for example using perl -pi -e 's,/usr/l,/tmp/\0,' /usr/local/bin/tesseract. Then try tesseract --list-langs to get the endless recursion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand, if the patched path is longer than the original one, the data in std::string is truncated. If so, it probably makes sense to call strlen() on the string literal rather than on c_str().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not possible to replace the original TESSDATA_PREFIX by a longer one because that would destroy other data. Therefore Conda uses a very long placeholder for TESSDATA_PREFIX.

@stweil stweil requested review from danpla and removed request for danpla May 15, 2024 14:53
@stweil stweil merged commit bcfdd5e into tesseract-ocr:main May 15, 2024
@stweil stweil deleted the issue4230 branch May 15, 2024 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants