提交 ddbb043a 编写于 作者: S Sam Judd

Return null from decoder if GifHeader has error.

上级 34cde327
package com.bumptech.glide.load.resource.gif;
import com.bumptech.glide.gifdecoder.GifDecoder;
import com.bumptech.glide.gifdecoder.GifHeader;
import com.bumptech.glide.gifdecoder.GifHeaderParser;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
......@@ -49,6 +50,24 @@ public class GifResourceDecoderTest {
assertNull(decoder.decode(new ByteArrayInputStream(new byte[0]), 100, 100));
}
@Test
public void testReturnsNullIfParsedHeaderHasFormatError() {
GifHeader header = mock(GifHeader.class);
when(parser.parseHeader()).thenReturn(header);
when(header.getStatus()).thenReturn(GifDecoder.STATUS_FORMAT_ERROR);
assertNull(decoder.decode(new ByteArrayInputStream(new byte[0]), 100, 100));
}
@Test
public void testReturnsNullIfParsedHeaderHasOpenError() {
GifHeader header = mock(GifHeader.class);
when(parser.parseHeader()).thenReturn(header);
when(header.getStatus()).thenReturn(GifDecoder.STATUS_OPEN_ERROR);
assertNull(decoder.decode(new ByteArrayInputStream(new byte[0]), 100, 100));
}
@Test
public void testReturnsParserToPool() throws IOException {
when(parserPool.obtain(any(byte[].class))).thenReturn(parser);
......
......@@ -60,7 +60,7 @@ public class GifResourceDecoder implements ResourceDecoder<InputStream, GifDrawa
private GifDrawableResource decode(byte[] data, int width, int height, GifHeaderParser parser) {
final GifHeader header = parser.parseHeader();
if (header.getNumFrames() <= 0) {
if (header.getNumFrames() <= 0 || header.getStatus() != GifDecoder.STATUS_OK) {
// If we couldn't decode the GIF, we will end up with a frame count of 0.
return null;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册