From 9c196bd2d500ba95598cd26e7e770c6b1645fca7 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Mon, 1 Jul 2019 16:31:40 -0400 Subject: [PATCH] Fix issue where an empty file could be read forever. If you gave the class an empty file, it would get back -1 for read(), causing it to fall forever into negative values, never escaping the existing conditions. The side effect of this was weird corner cases where these infinite reads could clog up threads, causing audio recordings to get blocked and such. Fixes #8898 --- .../securesms/crypto/ModernDecryptingPartInputStream.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/org/thoughtcrime/securesms/crypto/ModernDecryptingPartInputStream.java b/src/org/thoughtcrime/securesms/crypto/ModernDecryptingPartInputStream.java index e96da29dcf..e8c4e02c66 100644 --- a/src/org/thoughtcrime/securesms/crypto/ModernDecryptingPartInputStream.java +++ b/src/org/thoughtcrime/securesms/crypto/ModernDecryptingPartInputStream.java @@ -75,8 +75,9 @@ public class ModernDecryptingPartInputStream { for (;;) { int read = in.read(buffer, offset, buffer.length-offset); - if (read + offset < buffer.length) offset += read; - else return; + if (read == -1) throw new IOException("Prematurely reached end of stream!"); + else if (read + offset < buffer.length) offset += read; + else return; } }