Skip to content

Commit a9e320a

Browse files
authored
BXC-3225 - Virus max stream and filepath quoting (#1285)
* Set max stream size for virus scanning when using INSTREAM * Quote filepath during FITS commandline call, improve error output
1 parent 8d62721 commit a9e320a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

Diff for: deposit/src/main/java/edu/unc/lib/deposit/validate/ExtractTechnicalMetadataJob.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,15 @@ private Document extractUsingWebService(PID objPid, Path stagedPath) {
378378

379379
private Document extractUsingCLI(PID objPid, Path stagedPath) {
380380
try {
381-
Process process = Runtime.getRuntime().exec(fitsCommandPath + " -i " + stagedPath);
381+
String escapedPath = stagedPath.toString().replaceAll("\"", "\\\\\"");
382+
String command = fitsCommandPath + " -i \"" + escapedPath + "\"";
383+
Process process = Runtime.getRuntime().exec(command);
382384
if (process.waitFor() != 0) {
383-
failJob(null, "Failed to generate report for {0}, script returned {1} with output:\n{2}",
384-
objPid, process.exitValue(), IOUtils.toString(process.getInputStream(), UTF_8));
385+
String stdout = IOUtils.toString(process.getInputStream(), UTF_8);
386+
String stderr = IOUtils.toString(process.getErrorStream(), UTF_8);
387+
failJob(null, "Failed to generate report for {0}, using command:\n{1}\n"
388+
+ "Script returned {3} with output:\n{4} {5}",
389+
objPid, command, process.exitValue(), stdout, stderr);
385390
}
386391
return createSAXBuilder().build(process.getInputStream());
387392
} catch (IOException | JDOMException | InterruptedException e) {

Diff for: deposit/src/main/webapp/WEB-INF/deposit-jobs-context.xml

+1
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@
197197
<constructor-arg type="java.lang.String" value="${clamd.host:localhost}" index="0" />
198198
<constructor-arg type="int" value="${clamd.port:3310}" index="1" />
199199
<constructor-arg type="int" value="${clamd.timeout:60000}" index="2" />
200+
<property name="maxStreamSize" value="${clamd.maxStreamSize:64000000}" />
200201
</bean>
201202

202203
<bean id="fileValidationExecutor" class="java.util.concurrent.Executors"

0 commit comments

Comments
 (0)