From 383ac4fca01289139ab9e7d7e41d6fdf97a3df90 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 22 Feb 2024 19:50:36 +1100 Subject: [PATCH] Fixed reading PNG iCCP compression method --- Tests/images/unknown_compression_method.png | Bin 0 -> 4128 bytes Tests/test_file_png.py | 4 ++++ src/PIL/PngImagePlugin.py | 4 ++-- 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 Tests/images/unknown_compression_method.png diff --git a/Tests/images/unknown_compression_method.png b/Tests/images/unknown_compression_method.png new file mode 100644 index 0000000000000000000000000000000000000000..e1614a731a5ff0126513cd21d448e42cb084d5b1 GIT binary patch literal 4128 zcmV+*5Z~{KP)4Tx0gaQ(YZO@&hrjCFppYO8w69(amsv=VB$N*{B0kbdY@)Gk%0!bONT>RC zcbS{&np@Rz6cNeBrOq&W@v(5>AK=1;E8Qp&d?AQ?6-5->sI-gfbXV|sR$u+jxxaJH zEiQE0#URir33GmAoLp8;PEE@d&q%SJE;4i#-7pv|6vhCGL7@32K0d($c-Z&-{7<8+ z6uNU@t%TJ3k_uhu_zcu4lT*_mG>|?S1rdmIK-$Fm|3G>s=IcP(j5|XhZUL*@z(gSK z0RwKeSb|Og^i~ozGYOv4b+&d|COK@|W zTQ~DfYsr*Jv(WjX(fF_dR{RHF{%tfqU1>DFT!oJ3a9e)`&gs+100009a7bBm000XU000XU z0RWnu7ytka{z*hZRCt`-S_fEER~G)?R2Zs=f}k-rFeWNuqU+l7u^M%w?rK2A#1>0* zjZv1kVneZ_sMsN535rx}qDzc1+1Pv3pjc2T(tC4Y>Yn?CYQO*wcJp!h28R1?IsZNV z+{Y!xT-2kPH!dmWQu7D-;{N644>I||mF5pJCH7jAgJc_UuY51xl&f(@<2Ek!(Tyer z$#EQHG8xorHUC{Akw8_dfWH5o_-s<^lqSAV_)=YH=&RZ@!B z`>`1C{y@b3`T#0bDSG#PkGQI@WNlN>kskL;lPxbdGD7ISV0f?a#q60=P@vTy;$Q@} z?%IT)oqL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#5Y+Mhazv}Nm{j!%KKl?`5Ay@{6poPieZ zV~{laOG6DvCx-HN4BD(;2u-iIvBAd|-abokJn}ev*KL8X-)gu`bj2qVXQFjWOKjP` z5rMn+A~fO{+S=P;^zb1V>+T9Man57@B4lOfAUHS>NiS01HD>{`bMoLmV-nol-S{!J z-GFhK&uhMf6&cBp7x`~wuJ%X!llvia?118nWFW@RMr$8WSWFy?gppIAD^;T1fo;g% z7Xp!qDXjl774a_a5ZhV7e$OVP6BwiJZ===hDNq#@@;W}rZ7QrREfIL=DI0*zQ;d6EZ-F zZZl!MXfElX7%9^i!2WO`WbN#b=sF9w{woM*SIEd{Ub=W0b7sxQ!H~V^)9+n`9zKGg zuMXgwZ^Llw_C2gzvI-twevV5we!;RO|KwA?)jk_Aa>Nj<+O!iMb7#P*$2%DBJ{>!D zY($Tq@1R7fF?2I^D5-+i$u}c z3uw9cGn8Dv4Nc)o*ev=SnZCPF`XCNgp3_lu<|i^f7O?!-6{_b6upBlBGiT0+m8mKG z{MYg!TtL8noI3L(f_7~{bo3AK-?AHyT{>X{iL$~}fvvtax%gWT{`pEbT@9^K?`#;m=MSoEi4f8@F^s$NKLNHl4$AF zxg+8dl2Ab6+s3{PMvNQ=GqU75T`fA9_V{|Od^Q9CB0fphmnEzs(i2s38j`1Zz}9a$ zjC*xAJR>(z`sf+b<}QZa*IOZbvmNhB^rSDmdtnRGNi$c#^io$=%3$t*ML}v>g9Qdm zJXzez+=rB`JF~9kW7#uiMcFv!Ewx(195z?~ngD`JeR#EAu`6>C`60)VA9ez5BLav^ z65i>v{_M?rp}c+z_8~hcvK None: + with pytest.raises(SyntaxError, match="Unknown compression method"): + PngImagePlugin.PngImageFile("Tests/images/unknown_compression_method.png") + def test_padded_idat(self) -> None: # This image has been manually hexedited # so that the IDAT chunk has padding at the end diff --git a/src/PIL/PngImagePlugin.py b/src/PIL/PngImagePlugin.py index 823f12492..d864fd201 100644 --- a/src/PIL/PngImagePlugin.py +++ b/src/PIL/PngImagePlugin.py @@ -392,8 +392,8 @@ class PngStream(ChunkStream): # Compressed profile n bytes (zlib with deflate compression) i = s.find(b"\0") logger.debug("iCCP profile name %r", s[:i]) - logger.debug("Compression method %s", s[i]) - comp_method = s[i] + comp_method = s[i + 1] + logger.debug("Compression method %s", comp_method) if comp_method != 0: msg = f"Unknown compression method {comp_method} in iCCP chunk" raise SyntaxError(msg)