From fad697ba2a20ddc177e97c54e236415911d3a9d0 Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Thu, 13 Apr 2017 12:21:38 -0700 Subject: [PATCH] Fix CipherInputStream seek behavior Fixes #6518 // FREEBIE --- .../crypto/DecryptingPartInputStream.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/org/thoughtcrime/securesms/crypto/DecryptingPartInputStream.java b/src/org/thoughtcrime/securesms/crypto/DecryptingPartInputStream.java index 33037c0b63..56ca56d7c3 100644 --- a/src/org/thoughtcrime/securesms/crypto/DecryptingPartInputStream.java +++ b/src/org/thoughtcrime/securesms/crypto/DecryptingPartInputStream.java @@ -19,6 +19,7 @@ package org.thoughtcrime.securesms.crypto; import android.util.Log; import org.thoughtcrime.securesms.util.LimitedInputStream; +import org.thoughtcrime.securesms.util.Util; import java.io.File; import java.io.FileInputStream; @@ -139,5 +140,30 @@ public class DecryptingPartInputStream { Log.w(TAG, t); } } + + @Override + public long skip(long skipAmount) + throws IOException + { + long remaining = skipAmount; + + if (skipAmount <= 0) { + return 0; + } + + byte[] skipBuffer = new byte[4092]; + + while (remaining > 0) { + int read = super.read(skipBuffer, 0, Util.toIntExact(Math.min(skipBuffer.length, remaining))); + + if (read < 0) { + break; + } + + remaining -= read; + } + + return skipAmount - remaining; + } } }