From 0ba6abea4681eb0e18fe35a1c99e8f0d420c3996 Mon Sep 17 00:00:00 2001 From: Henrik Alstad-Kontio Date: Fri, 9 Aug 2019 19:56:16 +0200 Subject: [PATCH] Fixed potential array out of bounds exception, and an issue where we would not read the entire server response --- src/main/java/fi/solita/clamav/ClamAVClient.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/fi/solita/clamav/ClamAVClient.java b/src/main/java/fi/solita/clamav/ClamAVClient.java index 7f14e11..e76f11f 100644 --- a/src/main/java/fi/solita/clamav/ClamAVClient.java +++ b/src/main/java/fi/solita/clamav/ClamAVClient.java @@ -154,10 +154,9 @@ private static byte[] readAll(InputStream is) throws IOException { byte[] buf = new byte[2000]; int read = 0; - do { - read = is.read(buf); - tmp.write(buf, 0, read); - } while ((read > 0) && (is.available() > 0)); + while ((read = is.read(buf)) != -1) { + tmp.write(buf, 0, read); + } return tmp.toByteArray(); } }