Limit tile size to avoid extending outside image

This commit is contained in:
Andrew Murray 2022-06-16 08:36:43 +10:00
parent e80ddfd2b6
commit 4d6e5a0d09
4 changed files with 17 additions and 3 deletions

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 477 B

View File

@ -2,11 +2,22 @@ import pytest
from PIL import Image from PIL import Image
from .helper import assert_image_equal_tofile
FpxImagePlugin = pytest.importorskip( FpxImagePlugin = pytest.importorskip(
"PIL.FpxImagePlugin", reason="olefile not installed" "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(): def test_invalid_file():
# Test an invalid OLE file # Test an invalid OLE file
invalid_file = "Tests/images/flower.jpg" invalid_file = "Tests/images/flower.jpg"

View File

@ -154,13 +154,16 @@ class FpxImageFile(ImageFile.ImageFile):
for i in range(0, len(s), length): for i in range(0, len(s), length):
x1 = min(xsize, x + xtile)
y1 = min(ysize, y + ytile)
compression = i32(s, i + 8) compression = i32(s, i + 8)
if compression == 0: if compression == 0:
self.tile.append( self.tile.append(
( (
"raw", "raw",
(x, y, x + xtile, y + ytile), (x, y, x1, y1),
i32(s, i) + 28, i32(s, i) + 28,
(self.rawmode,), (self.rawmode,),
) )
@ -172,7 +175,7 @@ class FpxImageFile(ImageFile.ImageFile):
self.tile.append( self.tile.append(
( (
"fill", "fill",
(x, y, x + xtile, y + ytile), (x, y, x1, y1),
i32(s, i) + 28, i32(s, i) + 28,
(self.rawmode, s[12:16]), (self.rawmode, s[12:16]),
) )
@ -201,7 +204,7 @@ class FpxImageFile(ImageFile.ImageFile):
self.tile.append( self.tile.append(
( (
"jpeg", "jpeg",
(x, y, x + xtile, y + ytile), (x, y, x1, y1),
i32(s, i) + 28, i32(s, i) + 28,
(rawmode, jpegmode), (rawmode, jpegmode),
) )