diff options
author | Sam Judd <judds@google.com> | 2014-08-02 11:26:29 -0700 |
---|---|---|
committer | Sam Judd <judds@google.com> | 2014-08-03 09:15:24 -0700 |
commit | 548ff09b7c987156a3f927e8988d798959a0e575 (patch) | |
tree | e42a73a32d09853e201d42b1ec93f19b6810c68b /third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifHeaderParser.java | |
parent | 2e698748d344b36ca2f866babf7482e38355ccbe (diff) | |
download | glide-548ff09b7c987156a3f927e8988d798959a0e575.tar.gz |
Fix concurrency exceptions in GifResourceDecoder.
Diffstat (limited to 'third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifHeaderParser.java')
-rw-r--r-- | third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifHeaderParser.java | 35 |
1 files changed, 8 insertions, 27 deletions
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 9711bb1d..c5cde912 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 @@ -20,16 +20,15 @@ public class GifHeaderParser { */ private static final int MAX_STACK_SIZE = 4096; - private ByteBuffer rawData; - private GifHeader header; - // Raw data read working array. - private byte[] block = new byte[256]; + private final byte[] block = new byte[256]; // Block size last graphic control extension info. + private final short[] prefix = new short[MAX_STACK_SIZE]; + private final byte[] suffix = new byte[MAX_STACK_SIZE]; + + private ByteBuffer rawData; + private GifHeader header; private int blockSize = 0; - private short[] prefix; - private byte[] suffix; - private byte[] pixelStack; public GifHeaderParser setData(byte[] data) { reset(); @@ -49,9 +48,6 @@ public class GifHeaderParser { Arrays.fill(block, (byte) 0); header = new GifHeader(); blockSize = 0; - prefix = null; - suffix = null; - pixelStack = null; } public GifHeader parseHeader() { @@ -285,7 +281,7 @@ public class GifHeaderParser { } /** - * Decodes LZW image data into pixel array. Adapted from John Cristy's BitmapMagick. + * Skips LZW image data for a single frame to advance buffer. Adapted from John Cristy's BitmapMagick. */ protected void skipBitmapData() { int nullCode = -1; @@ -293,16 +289,6 @@ public class GifHeaderParser { int available, clear, codeMask, codeSize, endOfInformation, inCode, oldCode, bits, code, count, i, datum, dataSize, first, top, bi; - if (prefix == null) { - prefix = new short[MAX_STACK_SIZE]; - } - if (suffix == null) { - suffix = new byte[MAX_STACK_SIZE]; - } - if (pixelStack == null) { - pixelStack = new byte[MAX_STACK_SIZE + 1]; - } - // Initialize GIF data stream decoder. dataSize = read(); clear = 1 << dataSize; @@ -318,7 +304,7 @@ public class GifHeaderParser { } // Decode GIF pixel stream. - datum = bits = count = first = top = bi = 0; + datum = bits = count = top = bi = 0; for (i = 0; i < npix; ) { if (top == 0) { if (bits < codeSize) { @@ -354,18 +340,14 @@ public class GifHeaderParser { continue; } if (oldCode == nullCode) { - pixelStack[top++] = suffix[code]; oldCode = code; - first = code; continue; } inCode = code; if (code == available) { - pixelStack[top++] = (byte) first; code = oldCode; } while (code > clear) { - pixelStack[top++] = suffix[code]; code = prefix[code]; } first = ((int) suffix[code]) & 0xff; @@ -373,7 +355,6 @@ public class GifHeaderParser { if (available >= MAX_STACK_SIZE) { break; } - pixelStack[top++] = (byte) first; prefix[available] = (short) oldCode; suffix[available] = (byte) first; available++; |