JAL-2656 better read of (potential) gzip magic bytes
authorBen Soares <b.soares@dundee.ac.uk>
Thu, 20 Aug 2020 13:55:50 +0000 (14:55 +0100)
committerBen Soares <b.soares@dundee.ac.uk>
Thu, 20 Aug 2020 13:55:50 +0000 (14:55 +0100)
src/jalview/io/FileParse.java

index 3726c6b..d986dc5 100755 (executable)
@@ -219,18 +219,24 @@ public class FileParse
    * @param bytes
    *          - at least two bytes
    * @return
-   * @throws IOException 
+   * @throws IOException
    */
   public static boolean isGzipStream(InputStream input) throws IOException
   {
     if (!input.markSupported())
     {
-      Cache.log.error("FileParse.izGzipStream: input stream must support mark/reset");
+      Cache.log.error(
+              "FileParse.izGzipStream: input stream must support mark/reset");
       return false;
     }
     input.mark(4);
-    byte[] bytes = { (byte) input.read(), (byte) input.read() }; // input.readNBytes(2);
+    byte[] bytes = new byte[2]; // input.readNBytes(2);
+    int read = input.read(bytes);
     input.reset();
+    if (read != bytes.length)
+    {
+      return false;
+    }
     if (bytes.length == 2)
     {
       int header = (bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00);