From b5f2e4a4a093c651dd0bdc5c9894b6e57da90c43 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Wed, 3 Jul 2024 17:42:56 +0200 Subject: [PATCH] Ignore illegal TESSDATA_PREFIX (not existing filesystem entry, issue #4277) Don't check for a directory, because a symbolic link is also allowed. Signed-off-by: Stefan Weil --- src/ccutil/ccutil.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ccutil/ccutil.cpp b/src/ccutil/ccutil.cpp index 7cf57f2ee9..483d5bc1ee 100644 --- a/src/ccutil/ccutil.cpp +++ b/src/ccutil/ccutil.cpp @@ -17,7 +17,8 @@ #include "ccutil.h" #include -#include // for std::strrchr +#include // for std::strrchrA +#include // for std::filesystem namespace tesseract { @@ -48,6 +49,12 @@ void CCUtil::main_setup(const std::string &argv0, const std::string &basename) { const char *tessdata_prefix = getenv("TESSDATA_PREFIX"); + // Ignore TESSDATA_PREFIX if there is no matching filesystem entry. + if (tessdata_prefix != nullptr && !std::filesystem::exists(tessdata_prefix)) { + tprintf("Warning: TESSDATA_PREFIX %s does not exist, ignore it\n", tessdata_prefix); + tessdata_prefix = nullptr; + } + if (!argv0.empty()) { /* Use tessdata prefix from the command line. */ datadir = argv0;