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

Fix setup of datadir on installations with Conda (issue #4230) #4240

Merged
merged 1 commit into from
May 15, 2024

Conversation

stweil
Copy link
Contributor

@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
Contributor 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
Contributor 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
Contributor 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
6 of 7 checks passed
@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