diff --git a/deposit-app/src/main/java/edu/unc/lib/boxc/deposit/validate/VirusScanJob.java b/deposit-app/src/main/java/edu/unc/lib/boxc/deposit/validate/VirusScanJob.java
index da44308328..dcc3be253a 100644
--- a/deposit-app/src/main/java/edu/unc/lib/boxc/deposit/validate/VirusScanJob.java
+++ b/deposit-app/src/main/java/edu/unc/lib/boxc/deposit/validate/VirusScanJob.java
@@ -42,6 +42,7 @@ public class VirusScanJob extends AbstractConcurrentDepositJob {
.getLogger(VirusScanJob.class);
private static final int MAX_RETRIES = 5;
+ private long maxStreamSize;
private ClamAVClient clamClient;
@@ -97,18 +98,20 @@ public void runJob() {
Path file = Paths.get(fileURI);
ScanResult result;
- // Clamd is unable to find files with unicode characters in their path
- if (charactersInBoundsForClam(file)) {
- result = clamClient.scanWithResult(file);
- } else {
- // Scan files with unicode in their paths via streaming
- try {
+ try {
+ if (shouldScanByPath(file)) {
+ // Scan entire file by path
+ log.debug("Scanning file {} by path", file);
+ result = clamClient.scanWithResult(file);
+ } else {
+ // Scanning via InputStream up to the max number of bytes
+ log.debug("Scanning file {} by stream", file);
result = clamClient.scanWithResult(Files.newInputStream(file));
- } catch (IOException e) {
- failures.put(fileURI.toString(), "Failed to scan file");
- log.error("Unable to scan file {}", file, e);
- return;
}
+ } catch (IOException e) {
+ failures.put(fileURI.toString(), "Failed to scan file");
+ log.error("Unable to scan file {}", file, e);
+ return;
}
switch (result.getStatus()) {
@@ -180,8 +183,23 @@ private boolean charactersInBoundsForClam(Path path) {
return CharMatcher.ascii().matchesAllOf(path.toString());
}
+ /**
+ * Determines if we should scan a file by its file path or use streaming. Files larger than the scanning
+ * limit or with characters in their path that clamd can't handle will return false.
+ * @param path
+ * @return
+ * @throws IOException
+ */
+ private boolean shouldScanByPath(Path path) throws IOException {
+ return Files.size(path) < this.maxStreamSize && charactersInBoundsForClam(path);
+ }
+
// unused, no results to flush
@Override
protected void registrationAction() {
}
-}
\ No newline at end of file
+
+ public void setMaxStreamSize(long maxStreamSize) {
+ this.maxStreamSize = maxStreamSize;
+ }
+}
diff --git a/deposit-app/src/main/webapp/WEB-INF/deposit-jobs-context.xml b/deposit-app/src/main/webapp/WEB-INF/deposit-jobs-context.xml
index d553496622..98ede9e199 100644
--- a/deposit-app/src/main/webapp/WEB-INF/deposit-jobs-context.xml
+++ b/deposit-app/src/main/webapp/WEB-INF/deposit-jobs-context.xml
@@ -191,6 +191,7 @@
+