-
Notifications
You must be signed in to change notification settings - Fork 39
Document and fail fast if tmp directory is noexec #252
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
Changes from 4 commits
57f8bbe
9dca8a9
cc2ec93
862e4ac
80f3ffb
44d031f
c772b46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -128,6 +128,8 @@ public class Converter implements Callable<Integer> { | |
| private volatile Path inputPath; | ||
| private volatile String outputLocation; | ||
|
|
||
| private volatile boolean warnNoExec = false; | ||
|
|
||
| private Map<String, String> outputOptions; | ||
| private volatile Integer pyramidResolutions; | ||
| private volatile List<Integer> seriesList; | ||
|
|
@@ -409,6 +411,23 @@ public void setProgressBars(boolean useProgressBars) { | |
| progressBars = useProgressBars; | ||
| } | ||
|
|
||
| /** | ||
| * Configure whether to warn instead of throwing an exception | ||
| * if files created in the temporary directory | ||
| * ("java.io.tmpdir" system property) will not be executable. | ||
| * | ||
| * @param warnOnly true if a warning should be logged instead of an exception | ||
| */ | ||
| @Option( | ||
| names = {"--warn-no-exec"}, | ||
| description = "Warn instead of throwing an exception if " + | ||
| "java.io.tmpdir is not executable", | ||
| defaultValue = "false" | ||
| ) | ||
| public void setWarnOnNoExec(boolean warnOnly) { | ||
| warnNoExec = warnOnly; | ||
| } | ||
|
|
||
| /** | ||
| * Configure whether to print version information and exit | ||
| * without converting. | ||
|
|
@@ -944,6 +963,14 @@ public boolean getProgressBars() { | |
| return progressBars; | ||
| } | ||
|
|
||
| /** | ||
| * @return true if a warning is logged instead of an exception when the tmp | ||
| * directory is noexec | ||
| */ | ||
| public boolean getWarnNoExec() { | ||
| return warnNoExec; | ||
| } | ||
|
|
||
| /** | ||
| * @return true if only version info is displayed | ||
| */ | ||
|
|
@@ -1172,6 +1199,31 @@ public Integer call() throws Exception { | |
| tileWidth, tileHeight); | ||
| } | ||
|
|
||
| // if the tmpdir is mounted as noexec, then any native library | ||
| // loading (OpenCV, turbojpeg, etc.) is expected to fail, which | ||
| // can cause conversion to fail with an exception that is not user friendly | ||
| // | ||
| // try to detect this case early and fail before the conversion begins, | ||
| // with a more informative message | ||
|
|
||
| // a temp file is created and set as executable | ||
| // in the noexec case, setting as executable is expected to silently fail | ||
| File tmpdirCheck = File.createTempFile("noexec-test", ".txt"); | ||
| // expect 'success' to be true in the noexec case, even though | ||
| // the file will not actually be executable | ||
| boolean success = tmpdirCheck.setExecutable(true); | ||
| if (!success || !tmpdirCheck.canExecute()) { | ||
| String msg = System.getProperty("java.io.tmpdir") + | ||
| " is noexec; fix it or specify a different java.io.tmpdir"; | ||
| if (getWarnNoExec()) { | ||
| LOGGER.warn(msg); | ||
| } | ||
| else { | ||
| throw new RuntimeException(msg); | ||
| } | ||
| } | ||
| tmpdirCheck.delete(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the scenario where |
||
|
|
||
| OpenCVTools.loadOpenCV(); | ||
|
|
||
| if (progressBars) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.