Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit FPX tile size to avoid extending outside image #6368

Merged
merged 1 commit into from Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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