diff --git a/Tests/images/hopper_zero_comment_subblocks.gif b/Tests/images/hopper_zero_comment_subblocks.gif new file mode 100644 index 000000000..5f482c042 Binary files /dev/null and b/Tests/images/hopper_zero_comment_subblocks.gif differ diff --git a/Tests/test_file_gif.py b/Tests/test_file_gif.py index cfa1bb1e7..ffaff7afe 100644 --- a/Tests/test_file_gif.py +++ b/Tests/test_file_gif.py @@ -435,6 +435,11 @@ class TestFileGif(PillowTestCase): self.assertEqual(reread.info['comment'], im.info['comment']) + def test_zero_comment_subblocks(self): + im = Image.open('Tests/images/hopper_zero_comment_subblocks.gif') + expected = Image.open(TEST_GIF) + self.assert_image_equal(im, expected) + def test_version(self): out = self.tempfile('temp.gif') diff --git a/src/PIL/GifImagePlugin.py b/src/PIL/GifImagePlugin.py index ecd993cd5..f8d42e6fd 100644 --- a/src/PIL/GifImagePlugin.py +++ b/src/PIL/GifImagePlugin.py @@ -202,6 +202,8 @@ class GifImageFile(ImageFile.ImageFile): # comment extension # info["comment"] = block + if not block: + continue elif i8(s) == 255: # # application extension