From cbdc7516280776945579d14c017a0d636a9df9e4 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 10 Aug 2021 07:04:36 +1000 Subject: [PATCH] Read AND mask from end --- Tests/images/hopper_mask.ico | Bin 0 -> 262 bytes Tests/images/hopper_mask.png | Bin 0 -> 208 bytes Tests/test_file_ico.py | 5 +++++ src/PIL/IcoImagePlugin.py | 2 +- 4 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 Tests/images/hopper_mask.ico create mode 100644 Tests/images/hopper_mask.png diff --git a/Tests/images/hopper_mask.ico b/Tests/images/hopper_mask.ico new file mode 100644 index 0000000000000000000000000000000000000000..e8d66c689fd42918c887a316f34a8e0d3ae8c154 GIT binary patch literal 262 zcmZQzU<5(|0R|voWcUCi#ei4?h(SUMKn#)x0S6#H!Uw@jKsE@2z<(eB(WVVRwX8sK zP6h^MAls>vfx&}^fkEU61B2iT1_s_L28MSJ7#LdT0~I#{)dDSQ{l~z-X#g|>C^V25 E0C?>&ZU6uP literal 0 HcmV?d00001 diff --git a/Tests/images/hopper_mask.png b/Tests/images/hopper_mask.png new file mode 100644 index 0000000000000000000000000000000000000000..c7bd2f70842801aa0db7150ece834f839cf10376 GIT binary patch literal 208 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`(>+}rLn`L<21oN9Q4nZa_I!qfYIUFP)0s%}Q9FmwCmw=?2hLgO~cOSmGXm_xh*B`+Q&1olYF0)pbt5W}{+Q^;C{dV?S z8Hqw`c2h^It&)X%L^GPNyb5**di(nezsJ8iZi_u`3>6H8wpEfdPQP6NbRvVNtDnm{ Hr-UW|-Oo~i literal 0 HcmV?d00001 diff --git a/Tests/test_file_ico.py b/Tests/test_file_ico.py index 8060d1b763b..317264db646 100644 --- a/Tests/test_file_ico.py +++ b/Tests/test_file_ico.py @@ -18,6 +18,11 @@ def test_sanity(): assert im.get_format_mimetype() == "image/x-icon" +def test_mask(): + with Image.open("Tests/images/hopper_mask.ico") as im: + assert_image_equal_tofile(im, "Tests/images/hopper_mask.png") + + def test_black_and_white(): with Image.open("Tests/images/black_and_white.ico") as im: assert im.mode == "RGBA" diff --git a/src/PIL/IcoImagePlugin.py b/src/PIL/IcoImagePlugin.py index ffb1e873d23..d9ff9b5e731 100644 --- a/src/PIL/IcoImagePlugin.py +++ b/src/PIL/IcoImagePlugin.py @@ -235,8 +235,8 @@ def frame(self, idx): # the total mask data is # padded row size * height / bits per char - and_mask_offset = o + int(im.size[0] * im.size[1] * (bpp / 8.0)) total_bytes = int((w * im.size[1]) / 8) + and_mask_offset = header["offset"] + header["size"] - total_bytes self.buf.seek(and_mask_offset) mask_data = self.buf.read(total_bytes)