From ea3b66d8efdae18b2de923e0f7832191fb0cd5e1 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 29 Sep 2022 21:29:16 +1000 Subject: [PATCH] Allow palette chunk to not be first --- Tests/images/hopper_palette_chunk_second.fli | Bin 0 -> 16909 bytes Tests/test_file_fli.py | 8 +++++++- src/PIL/FliImagePlugin.py | 19 ++++++++++++++----- 3 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 Tests/images/hopper_palette_chunk_second.fli diff --git a/Tests/images/hopper_palette_chunk_second.fli b/Tests/images/hopper_palette_chunk_second.fli new file mode 100644 index 0000000000000000000000000000000000000000..54447de0af71d9ae5de4b149bbe86f032a28e9e7 GIT binary patch literal 16909 zcmbumcU+Tq7dD>cd*{v$2|+*!D})sYARr>(WXV!%6%<^p3J8u?k>M=Uf#6_^TAwPi z(F%_iQOgXQB8XZL9Egeokv$Ulotx+V{QiGGZxcvB>vgU(u5-R4+*Kr!@@+EdH+axV zh-5_ifBWyZ|I7b9aV3c~^_}wn|6hlekw{7;cE6KU)5+CL&vf-VH+NSTSJ!pxRy#U5 zIwH4!+?}O<6K&Vd_4%24d9m!StiUX9jwz-lN2f+-*KElC<3E4==RdjE|9kyEfBbRl zR(AIF|DZocvr4kE;fGt^aCwuNIE9*Zf8|BVqU*~2|=YT0$)a;3z+}y&#+qa9c!r2mf z3qZQMnh8a2>)fTTZq6=l>s%a7937q4xj8y|-1KuuSz&JGxNe=%(kl*nZXOn%Hs8@? z$9SvRnl&C4Yu7AVyJq9&TO}peORfXtA3!hbdJX{H%Ff9txejk~ux$DD?Ce}T`}_6l zx$q|U4uK7vQ6cYxlL>%Jg`(A~-A!Dbon2OYxk$}S9G$(8Tcd@yjrTPNBQvnb$gao1 z(cQ&kwbh`!_1<$E^F<36dfz+Y?OeEq-Kf7}4~W}zIEJDW|-QDhO`ohA_B zRgsmOi?U~K<>TPz;zIVY$sB1tk=JTR6DQ<0OL%HCOyh5N{2;nVZ6d0SDxVV}KO`;1Oa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-PiIzt-|zz>=apR_T65t^3p( ze=&ctUsP=Bo@((!v)&Ksn_SLqbSv8Ik`%l)*Wcy-9@o+kx10d)(s1vhgX_;7I#7H# z@Y2TpvLLs*Q1`lU?~Wrr4F`T`Iug+7zw_S&qyL`rPCj+0`O_?~^Jv+D5D zz!JNFT>I_U)(51796IL|ROlL*yVC!zQ*g2CzWeUK-t#>4z~$h*A3`5)IQqyZ;@*!3 z^Y%!lWTrWZVpeW3rcL?o78?Vxh*vP*};UiLn*zA$y963^%5XJ+5e&HXE{_-_84tNE8?nQ>23&VI{`uFXkrD>&bu9XFAEYV5!9 zAOD*^{a40t;l+mH!l|+w{daRa(u>+<#fs|eFHef5KNY{NONq{?FS^@WUsn72QB`~6 vKOZ_f2mWmw`}FLeC!arbzw7V&Fy8+`G5$#*pP3q;9Q-=g`S#82nkWAsa|(Zz literal 0 HcmV?d00001 diff --git a/Tests/test_file_fli.py b/Tests/test_file_fli.py index a7d43d2e9..b8b999d70 100644 --- a/Tests/test_file_fli.py +++ b/Tests/test_file_fli.py @@ -4,7 +4,7 @@ import pytest from PIL import FliImagePlugin, Image -from .helper import assert_image_equal_tofile, is_pypy +from .helper import assert_image_equal, assert_image_equal_tofile, is_pypy # created as an export of a palette image from Gimp2.6 # save as...-> hopper.fli, default options. @@ -79,6 +79,12 @@ def test_invalid_file(): FliImagePlugin.FliImageFile(invalid_file) +def test_palette_chunk_second(): + with Image.open("Tests/images/hopper_palette_chunk_second.fli") as im: + with Image.open(static_test_file) as expected: + assert_image_equal(im.convert("RGB"), expected.convert("RGB")) + + def test_n_frames(): with Image.open(static_test_file) as im: assert im.n_frames == 1 diff --git a/src/PIL/FliImagePlugin.py b/src/PIL/FliImagePlugin.py index e13b1779c..908bed9f4 100644 --- a/src/PIL/FliImagePlugin.py +++ b/src/PIL/FliImagePlugin.py @@ -15,6 +15,7 @@ # See the README file for information on usage and redistribution. # +import os from . import Image, ImageFile, ImagePalette from ._binary import i16le as i16 @@ -80,11 +81,19 @@ class FliImageFile(ImageFile.ImageFile): if i16(s, 4) == 0xF1FA: # look for palette chunk - s = self.fp.read(6) - if i16(s, 4) == 11: - self._palette(palette, 2) - elif i16(s, 4) == 4: - self._palette(palette, 0) + number_of_subchunks = i16(s, 6) + chunk_size = None + for _ in range(number_of_subchunks): + if chunk_size is not None: + self.fp.seek(chunk_size - 6, os.SEEK_CUR) + s = self.fp.read(6) + chunk_type = i16(s, 4) + if chunk_type in (4, 11): + self._palette(palette, 2 if chunk_type == 11 else 0) + break + chunk_size = i32(s) + if not chunk_size: + break palette = [o8(r) + o8(g) + o8(b) for (r, g, b) in palette] self.palette = ImagePalette.raw("RGB", b"".join(palette))