From b15eb801bc371fb2b7e147aa4ca90cbfb19899cf Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Thu, 20 Aug 2020 14:55:50 +0100 Subject: [PATCH] JAL-2656 better read of (potential) gzip magic bytes --- src/jalview/io/FileParse.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/jalview/io/FileParse.java b/src/jalview/io/FileParse.java index 3726c6b..d986dc5 100755 --- a/src/jalview/io/FileParse.java +++ b/src/jalview/io/FileParse.java @@ -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); -- 1.7.10.2