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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/ccutil/ccutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,10 @@ void CCUtil::main_setup(const std::string &argv0, const std::string &basename) {
if (datadir.empty()) {
#if defined(TESSDATA_PREFIX)
// Use tessdata prefix which was compiled in.
datadir = TESSDATA_PREFIX "/tessdata/";
// Note that some software (for example conda) patches TESSDATA_PREFIX
// in the binary, so it should not be used directly with a std::string.
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.

datadir.resize(std::strlen(datadir.c_str()));
#else
datadir = "./";
#endif /* TESSDATA_PREFIX */
Expand Down
Loading