aboutsummaryrefslogtreecommitdiff
path: root/third_party
diff options
context:
space:
mode:
authorSam Judd <judds@google.com>2014-07-11 09:05:24 -0700
committerSam Judd <judds@google.com>2014-07-11 19:02:29 -0700
commit5ce0c1172e076cd72af8efbde97cffca5f215ba1 (patch)
tree15ffa8f2d065c31bce288cafdf8ac5fc053c20c2 /third_party
parented2140817d86cc3ad9067d451c5fa0a6e362e04a (diff)
downloadglide-5ce0c1172e076cd72af8efbde97cffca5f215ba1.tar.gz
Fix exception when GIF can't be decoded
We get a GifHeader object, but it has 0 frames which eventually causes a divide by zero exception. Since the real problem is that we couldn't decode the gif, we check in the decoder if the decode failed and then simply return null.
Diffstat (limited to 'third_party')
-rw-r--r--third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifDecoder.java3
-rw-r--r--third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifHeader.java4
-rw-r--r--third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifHeaderParser.java19
3 files changed, 22 insertions, 4 deletions
diff --git a/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifDecoder.java b/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifDecoder.java
index 4d653cb5..ac90fc70 100644
--- a/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifDecoder.java
+++ b/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifDecoder.java
@@ -109,6 +109,7 @@ public class GifDecoder {
private GifHeader header;
private String id;
private BitmapProvider bitmapProvider;
+ private GifHeaderParser parser = new GifHeaderParser();
public interface BitmapProvider {
public Bitmap obtain(int width, int height, Bitmap.Config config);
@@ -308,7 +309,7 @@ public class GifDecoder {
*/
public int read(byte[] data) {
this.data = data;
- this.header = new GifHeaderParser(data).parseHeader();
+ this.header = parser.setData(data).parseHeader();
if (data != null) {
// Initialize the raw data buffer.
rawData = ByteBuffer.wrap(data);
diff --git a/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifHeader.java b/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifHeader.java
index a5e556a5..c4b03491 100644
--- a/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifHeader.java
+++ b/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifHeader.java
@@ -42,4 +42,8 @@ public class GifHeader {
public int getWidth() {
return width;
}
+
+ public int getNumFrames() {
+ return frameCount;
+ }
}
diff --git a/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifHeaderParser.java b/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifHeaderParser.java
index af1844d9..5bf122ba 100644
--- a/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifHeaderParser.java
+++ b/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifHeaderParser.java
@@ -5,6 +5,7 @@ import android.util.Log;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
+import java.util.Arrays;
import static com.bumptech.glide.gifdecoder.GifDecoder.STATUS_FORMAT_ERROR;
@@ -15,8 +16,8 @@ public class GifHeaderParser {
*/
private static final int MAX_STACK_SIZE = 4096;
- private final ByteBuffer rawData;
- private GifHeader header = new GifHeader();
+ private ByteBuffer rawData;
+ private GifHeader header;
// Raw data read working array.
private byte[] block = new byte[256];
@@ -26,7 +27,8 @@ public class GifHeaderParser {
private byte[] suffix;
private byte[] pixelStack;
- public GifHeaderParser(byte[] data) {
+ public GifHeaderParser setData(byte[] data) {
+ reset();
if (data != null) {
rawData = ByteBuffer.wrap(data);
rawData.rewind();
@@ -35,6 +37,17 @@ public class GifHeaderParser {
rawData = null;
header.status = GifDecoder.STATUS_OPEN_ERROR;
}
+ return this;
+ }
+
+ private void reset() {
+ rawData = null;
+ Arrays.fill(block, (byte) 0);
+ header = new GifHeader();
+ blockSize = 0;
+ prefix = null;
+ suffix = null;
+ pixelStack = null;
}
public GifHeader parseHeader() {