From 504580ff32fe6d4145a4447210e9d49b524aaa5c Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Mon, 7 Jul 2014 14:33:54 -0400 Subject: [PATCH] Fix buffering of file data in TikaFileTypeDetector class --- .../modules/filetypeid/TikaFileTypeDetector.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/TikaFileTypeDetector.java b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/TikaFileTypeDetector.java index 4e445f714c..b9ea8bc8a0 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/TikaFileTypeDetector.java +++ b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/TikaFileTypeDetector.java @@ -28,9 +28,9 @@ import org.sleuthkit.datamodel.AbstractFile; class TikaFileTypeDetector { - private static Tika tikaInst = new Tika(); //calling detect() with this should be thread-safe + private static final Tika tikaInst = new Tika(); //calling detect() with this should be thread-safe private final int BUFFER_SIZE = 64 * 1024; //how many bytes to pass in - private byte buffer[] = new byte[BUFFER_SIZE]; + private final byte buffer[] = new byte[BUFFER_SIZE]; /** * @@ -39,12 +39,19 @@ class TikaFileTypeDetector { */ public synchronized String attemptMatch(AbstractFile abstractFile) { try { + byte buf[]; int len = abstractFile.read(buffer, 0, BUFFER_SIZE); + if (len < BUFFER_SIZE) { + buf = new byte[len]; + System.arraycopy(buffer, 0, buf, 0, len); + } else { + buf = buffer; + } // the xml detection in Tika tries to parse the entire file and throws exceptions // for files that are not valid XML try { - String tagHeader = new String(buffer, 0, 5); + String tagHeader = new String(buf, 0, 5); if (tagHeader.equals("