From 8281ef18d42ec309a2f8fa08a03510af2b172eb6 Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Sat, 10 Aug 2013 09:09:00 -0700 Subject: [PATCH] Fix for ShortBufferException problem introduced in Android 4.3 Not really sure how it's possible for the system to give us an extra block of data, but it does if both the input and output buffers are sized the same during the first decrypt. This fixes things, but I wish I better understood why it was broken. --- .../securesms/crypto/DecryptingPartInputStream.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/org/thoughtcrime/securesms/crypto/DecryptingPartInputStream.java b/src/org/thoughtcrime/securesms/crypto/DecryptingPartInputStream.java index 15d97f19e..860f42467 100644 --- a/src/org/thoughtcrime/securesms/crypto/DecryptingPartInputStream.java +++ b/src/org/thoughtcrime/securesms/crypto/DecryptingPartInputStream.java @@ -126,7 +126,7 @@ public class DecryptingPartInputStream extends FileInputStream { length = (int)(totalDataSize - totalRead); byte[] internalBuffer = new byte[length]; - int read = super.read(internalBuffer, 0, internalBuffer.length); + int read = super.read(internalBuffer, 0, internalBuffer.length <= cipher.getBlockSize() ? internalBuffer.length : internalBuffer.length - cipher.getBlockSize()); totalRead += read; try {