From 958331a8ea9f6df8d7e292440c99929b1c307042 Mon Sep 17 00:00:00 2001 From: Cody Henthorne Date: Tue, 8 Jun 2021 16:46:01 -0400 Subject: [PATCH] Fix bug with APNGParser over reading larger files and invalidating the stream. --- .../glide/cache/ApngStreamCacheDecoder.java | 5 +++- .../securesms/glide/cache/LimitedReader.kt | 27 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/org/thoughtcrime/securesms/glide/cache/LimitedReader.kt diff --git a/app/src/main/java/org/thoughtcrime/securesms/glide/cache/ApngStreamCacheDecoder.java b/app/src/main/java/org/thoughtcrime/securesms/glide/cache/ApngStreamCacheDecoder.java index fdce779f78..37954ba1ee 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/glide/cache/ApngStreamCacheDecoder.java +++ b/app/src/main/java/org/thoughtcrime/securesms/glide/cache/ApngStreamCacheDecoder.java @@ -18,6 +18,9 @@ import java.nio.ByteBuffer; public class ApngStreamCacheDecoder implements ResourceDecoder { + /** Set to match {@link com.bumptech.glide.load.data.InputStreamRewinder}'s read limit */ + private static final int READ_LIMIT = 5 * 1024 * 1024; + private final ResourceDecoder byteBufferDecoder; public ApngStreamCacheDecoder(ResourceDecoder byteBufferDecoder) { @@ -27,7 +30,7 @@ public class ApngStreamCacheDecoder implements ResourceDecoder= readLimit) { + throw IOException("Read limit exceeded") + } + return reader.read(buffer, start, byteCount) + } + + @Throws(IOException::class) + override fun skip(total: Long): Long { + if (position() + total >= readLimit) { + throw IOException("Read limit exceeded") + } + return reader.skip(total) + } +}