From 4d6e5a0d095cc1567f286e470d7af286a3e8d50e Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 16 Jun 2022 08:36:43 +1000 Subject: [PATCH] Limit tile size to avoid extending outside image --- Tests/images/input_bw_one_band.fpx | Bin 0 -> 33792 bytes Tests/images/input_bw_one_band.png | Bin 0 -> 477 bytes Tests/test_file_fpx.py | 11 +++++++++++ src/PIL/FpxImagePlugin.py | 9 ++++++--- 4 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 Tests/images/input_bw_one_band.fpx create mode 100644 Tests/images/input_bw_one_band.png diff --git a/Tests/images/input_bw_one_band.fpx b/Tests/images/input_bw_one_band.fpx new file mode 100644 index 0000000000000000000000000000000000000000..9bdc53763fe9459ecc35cd45feabf15d06d6d124 GIT binary patch literal 33792 zcmeGk2Y6Fe_oSt?3}YE#1}%gcL>p#6;RVnlN(7-GYE_`DmO?2MDXt;{0xm{D6bIA= zPU?V)qkw`qP(&0I2OtjI8*tG7oIBpiY}5Y#$M3u8dFS4<@44$`yzY9Z-hnkG%?^U8 z^nrLdQCgYDC6R?sD5Qi0NpC~Uc=R^RkTID3lz&{vk4KaoZh-thN5t0Or#mbxcI0eCua4G^$0jP&iAE5z4Lj(sxBZS5XO%R$Qkd5Yuod_)uPD3~yAqAl&LMsH4 zX^prILR*A(2<;I%Ah;1aBAkKH3E@nHvk+1dJP4%Q1#wq|ZV25GdLVcadLr~fI2+*{ zgx&~!5EKL-0_pyn%TUP0S3Zu#c`ya>G?;~1$!pcQ;gTDZ*7S32DH-bc>D?}^r;VvK zr%~-Djhi)X+opXxcZY6Wdvx#V?cb{rB&cgX9yMXY=n?5#-mW)q7(5DVj$clsrHd9W zSh2il8LVmEdr*rVHj?wczX#Lv|$UluKt$&iS%E^-f95ObxgaZoR z1e_?xDWJaz;6qNsjwKl$KYX};m)%K_lG1q>%@G^E2vcc56NE4V?b(FW5ZI(aL~J?} zScNbaFA;?vwIlgA>ywUJqKMyy9^!F=(}zWX4lLZv>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RzLr=EHW z)~{a=B_$>B^wUqnGtWE&&p!JsJonsluwlan*tl^cl$Msl^UpsIn>KBN7hZS)UVQOI zcXCwr}4Kuf6sf?AWmbUVr^{ zc;k&X;LSJRgty*$3wG|@32(psHoWuBJFsilE_nCdcVYML-SFOf@4=oud*J=|--i!A z_yG3q-3$Bn?Sl_L{186+=p)#_e?NTu@yGDVC!fHlpMDCTefAj~IB)v`2$CXxlro30qD3liXw@~f&Kn_NP+RCdIQuuXDY*Ipj>k#OLsFcWG*LZwv-2uujU zXpPgPOD4&TYf%dxQAu0JVA6~&Y%&>Xi(`@}vS{ffG%DjUP9^M9Oj?(8Rh?h7&AjnQ zm?s&L8km+CUA)NUwp9XkI1_kkyb+iY>*s7Iw>i`?DNzy3qqd6RS~93f<)1g zHFGQwx|F(TCLJC$!E26-dbTn#_kO1Ov0TDVwLX#mP=-Y<6j>9bK+gk3q z51j+Ojq0|q_Z76RCB(#LJtA7z_)SWYnk<{#AX#SOCi{_0aK0KHHF+PX!m4Uh&r$Qw z^&?%Y+kO!LJR4$eif|2LoMs?Zs3G%0gCOgg0U}~cM4{0uT%$09*r&lDPRxZ_31+A& z?FU53j8{qg0j4E^yO6D_$JJ`TlBubJ`4A~l)$O9X?MLdLflt9$-#7D_Ue#CY`(JIU zS>OL!-~U?Q|NiU0|J61Gt7c`u%7B#tD+5*rtPEHgurgp}z{-G?0V@Mm2CNKN8L%>7 cWx&dSl>sXQRtBsLRBHyT?|-ZMn_q74KNZQI-v9sr literal 0 HcmV?d00001 diff --git a/Tests/images/input_bw_one_band.png b/Tests/images/input_bw_one_band.png new file mode 100644 index 0000000000000000000000000000000000000000..6b4c1f37696a847dc9859da93af8c6e1eec52eb7 GIT binary patch literal 477 zcmV<30V4j1P)jUe z_XDE!potni8@oajKyE?{?8Z%ECs8g#)@9yoW@kcW;BZE9i>uIBPxe}^*M_-BtxHm) z#&%_c(lJ}*c-uLY21#*P)t4(WiBB@7Z5?@LleG0V##ncOo~JrrDW-9e3m8SXEG41k zQ1ooVStIZKToK&(#R4kiwC;vq;Z`ffXh z2d$enH~Se(8Tk+^-q;G|m{7a}n>3st$)Emhao@qT5)o=Y?C2a(a)+nVz8CffiPcI% TjOZMM00000NkvXXu0mjf^4ivS literal 0 HcmV?d00001 diff --git a/Tests/test_file_fpx.py b/Tests/test_file_fpx.py index 818565f88..fa22e90f6 100644 --- a/Tests/test_file_fpx.py +++ b/Tests/test_file_fpx.py @@ -2,11 +2,22 @@ import pytest from PIL import Image +from .helper import assert_image_equal_tofile + FpxImagePlugin = pytest.importorskip( "PIL.FpxImagePlugin", reason="olefile not installed" ) +def test_sanity(): + with Image.open("Tests/images/input_bw_one_band.fpx") as im: + assert im.mode == "L" + assert im.size == (70, 46) + assert im.format == "FPX" + + assert_image_equal_tofile(im, "Tests/images/input_bw_one_band.png") + + def test_invalid_file(): # Test an invalid OLE file invalid_file = "Tests/images/flower.jpg" diff --git a/src/PIL/FpxImagePlugin.py b/src/PIL/FpxImagePlugin.py index f955b2347..a55376d0e 100644 --- a/src/PIL/FpxImagePlugin.py +++ b/src/PIL/FpxImagePlugin.py @@ -154,13 +154,16 @@ class FpxImageFile(ImageFile.ImageFile): for i in range(0, len(s), length): + x1 = min(xsize, x + xtile) + y1 = min(ysize, y + ytile) + compression = i32(s, i + 8) if compression == 0: self.tile.append( ( "raw", - (x, y, x + xtile, y + ytile), + (x, y, x1, y1), i32(s, i) + 28, (self.rawmode,), ) @@ -172,7 +175,7 @@ class FpxImageFile(ImageFile.ImageFile): self.tile.append( ( "fill", - (x, y, x + xtile, y + ytile), + (x, y, x1, y1), i32(s, i) + 28, (self.rawmode, s[12:16]), ) @@ -201,7 +204,7 @@ class FpxImageFile(ImageFile.ImageFile): self.tile.append( ( "jpeg", - (x, y, x + xtile, y + ytile), + (x, y, x1, y1), i32(s, i) + 28, (rawmode, jpegmode), )