-
Notifications
You must be signed in to change notification settings - Fork 393
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
Made temp directory creation respect the TMPDIR environment variable … #561
base: master
Are you sure you want to change the base?
Conversation
…rather than forcing it inside /tmp directory. When running inside some sandboxed environments /tmp will not be available.
That section needs to be surrounded by braces { ... }, as in the section above, because C only permits variables to be declared following an opening brace. Also, I note that you have pathJoin on line 3311, whereas the master has it on line 3287. Do you have a sandboxed unix environment with TMPDIR defined? |
Thanks. I'll amend it tomorrow. I'm using the Mac app sandbox which doesn't allow access to /tmp. In my particular environment I have TMPDIR defined but on environments that don't have it by default it is nice to at least have an option for configuring it from the environment. A better solution may be to just use mktemp() (or one of its variants) which, at least on Mac will use the system config temp dir, which the app always has access to even inside the sandbox. |
I have made the requested change (wrapped code in block for C89 compatibility). Just for the record, I experimented with an alternate fix in which I use the iOS path for getting the temp directory. E.g.
As this should have worked for OS X also. But this didn't seem fix my issue - the temp directory it retrieved was still not accessible. If I get some free time and more curiosity, I'll examine that path further, but for now having the ability to at least control it via environment variable |
This issue came up 5 years ago, during a major re-write of the code handling temp directories. Here's the problem. Putting your change int makeTempDirname() will not cause rewriting of temp directory names in general. So, for example, lept_mkdir() makes a pathname starting with "/tmp". This is done in genPathname(), which was the major target for fixing the temp directory issues. genPathname() explicitly states that TMPDIR is ignored in unix. It was done for simplicity, ease of maintenance and avoiding issues. For the latter, it worked for 5 years :-) It's not that this can't be done. For example, modifying
to
gets most of the way toward the unix path rewrite. (Some of the regression tests still fail) If you can't write to /tmp on your unix system, you'll need to use your workaround with TMPDIR. Dan |
It's puzzling to me that this hasn't been reported before. As far as I can tell this should affect all Mac versions when running in the sandbox. I.e. without this workaround Leptonica can't be used in Mac with sandbox enabled. |
Yes, it's a puzzle. You are the first to bring this up in 5 years.
…On Wed, Dec 30, 2020 at 12:20 PM Steve Hannah ***@***.***> wrote:
It's puzzling to me that this hasn't been reported before. As far as I can
tell this should affect all Mac versions when running in the sandbox. I.e.
without this workaround Leptonica can't be used in Mac with sandbox enabled.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#561 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AD7KMLDCUUGYJRGEZXZF7LLSXODSLANCNFSM4VN2QXBA>
.
|
@shannah, I use Tesseract OCR with Leptonica on MacOS (Intel since several years, now also M1) and don't have problems with Do you have an example how I can reproduce the problem? |
@@ -3308,7 +3308,14 @@ size_t pathlen; | |||
dir = pathJoin(result, subdir); | |||
} | |||
#else | |||
dir = pathJoin("/tmp", subdir); | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to use the OS_IOS
code above for MacOS, too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit 05ff50e uses the OS_IOS
code for MacOS, too. This makes the pull request here obsolete.
Are you using it in an app with sandbox enabled? |
No, I use Tesseract from the command line. Is it possible to "emulate" a sandbox environment? How? |
@shannah, does the terminal app run with sandbox enabled, or can I get a command line somehow with sandbox enabled? I still would like to reproduce the problem which should be fixed by this pull request. Or is this PR no longer needed? |
I haven't had to recompile it in a while, but last i tried, this patch was necessary to run inside sandbox. It may be possible to emulate the sandbox using the sandbox-exec command (https://paolozaino.wordpress.com/2015/08/04/how-to-run-your-applications-in-a-mac-os-x-sandbox-to-enhance-security/) but i haven't tried this, and would require a sandbox config file to be created first. |
|
I could run
Obviously it depends on the sandbox configuration whether |
Yes. Apps in the appstore don't have a choice as to whether /tmp is writable, so to emulate that condition you would need to make it unwritable in the sandbox config. |
|
Makes sense. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
last i tried, this patch was necessary to run inside sandbox
I think that you would get a different result now.
This pull request is no longer needed because since commit 05ff50e MacOS uses the configured path for temporary files which should give the same result as using TMPDIR
.
@shannah, please try the latest code which should fix the issues with macOS applications running in the sandbox. Do you still think that |
…rather than forcing it inside /tmp directory. When running inside some sandboxed environments /tmp will not be available.