Skip to content

Commit

Permalink
Limit tile size to avoid extending outside image
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Jun 15, 2022
1 parent e80ddfd commit 4d6e5a0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
Binary file added Tests/images/input_bw_one_band.fpx
Binary file not shown.
Binary file added Tests/images/input_bw_one_band.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions Tests/test_file_fpx.py
Expand Up @@ -2,11 +2,22 @@

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"
Expand Down
9 changes: 6 additions & 3 deletions src/PIL/FpxImagePlugin.py
Expand Up @@ -154,13 +154,16 @@ def _open_subimage(self, index=1, subimage=0):

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,),
)
Expand All @@ -172,7 +175,7 @@ def _open_subimage(self, index=1, subimage=0):
self.tile.append(
(
"fill",
(x, y, x + xtile, y + ytile),
(x, y, x1, y1),
i32(s, i) + 28,
(self.rawmode, s[12:16]),
)
Expand Down Expand Up @@ -201,7 +204,7 @@ def _open_subimage(self, index=1, subimage=0):
self.tile.append(
(
"jpeg",
(x, y, x + xtile, y + ytile),
(x, y, x1, y1),
i32(s, i) + 28,
(rawmode, jpegmode),
)
Expand Down

0 comments on commit 4d6e5a0

Please sign in to comment.