From 5056850a2f0a54f27e4117cbe26abe468e4405bc Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 20 Oct 2023 16:09:13 +1100 Subject: [PATCH] Seek past the data when skipping a layer --- Tests/images/five_channels.psd | Bin 0 -> 1120 bytes Tests/test_file_psd.py | 5 +++++ src/PIL/PsdImagePlugin.py | 3 +++ 3 files changed, 8 insertions(+) create mode 100644 Tests/images/five_channels.psd diff --git a/Tests/images/five_channels.psd b/Tests/images/five_channels.psd new file mode 100644 index 0000000000000000000000000000000000000000..021a5fa633bf9989b728018e58f6c950a604370a GIT binary patch literal 1120 zcmaJFeA*5AW_0auEwxQWg*v%pZkAl~N z2Y)VBJ$Uh~R}WqVL8uDi)r(#fy+~cZdE2-lG!DEs-V0CT+pGZ)2tlz16f_$3$r!A^9Mn5#VBuXT`Nz0K>;OX zv4Em!hyCS7qb`h-<=0_S+q)&nb#lx^Ytdf~^s3?*txWE-V<>5F!}j@e%B0O0K<;xK|5yN~?gB^qas2yn93MRaGM|7~e#-A10M(zg@29rP zBVhJ6@Zxo9v+e;e?*Q{3`(|LOdt|osb{qKq3@B~^r``gE>q+0}6F;852R7KN`WxWE zL*T5-+&3n?dzyrQefw|BasT+wSGk&;+f+0{4Y@d`&MR|X&0k(c<>NnMmnrvqfhR$f zZ7!LHp(HtuPX)uYcio^DaR`Lhjr^IQcO{1Y3ya1ro_BL1$UV(e}}zr1K%lHA!z y^^H|l8`5)ibFammBNfcimqVQu?4iZ`6W{pF8s8nW1Ja}MJ+Y7OqcOT-lJ*zu@1>;x literal 0 HcmV?d00001 diff --git a/Tests/test_file_psd.py b/Tests/test_file_psd.py index e405834b5ca..708212fa682 100644 --- a/Tests/test_file_psd.py +++ b/Tests/test_file_psd.py @@ -111,6 +111,11 @@ def test_rgba(): assert_image_equal_tofile(im, "Tests/images/imagedraw_square.png") +def test_layer_skip(): + with Image.open("Tests/images/five_channels.psd") as im: + assert im.n_frames == 1 + + def test_icc_profile(): with Image.open(test_file) as im: assert "icc_profile" in im.info diff --git a/src/PIL/PsdImagePlugin.py b/src/PIL/PsdImagePlugin.py index 2f019bb8c34..46970da049b 100644 --- a/src/PIL/PsdImagePlugin.py +++ b/src/PIL/PsdImagePlugin.py @@ -186,6 +186,9 @@ def read(size): ct_types = i16(read(2)) types = list(range(ct_types)) if len(types) > 4: + fp.seek(len(types) * 6 + 12, io.SEEK_CUR) + size = i32(read(4)) + fp.seek(size, io.SEEK_CUR) continue for _ in types: