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("