Skip to content

Commit 4d6e5a0

Browse files
committed
Limit tile size to avoid extending outside image
1 parent e80ddfd commit 4d6e5a0

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

Tests/images/input_bw_one_band.fpx

33 KB
Binary file not shown.

Tests/images/input_bw_one_band.png

477 Bytes
Loading

Tests/test_file_fpx.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,22 @@
22

33
from PIL import Image
44

5+
from .helper import assert_image_equal_tofile
6+
57
FpxImagePlugin = pytest.importorskip(
68
"PIL.FpxImagePlugin", reason="olefile not installed"
79
)
810

911

12+
def test_sanity():
13+
with Image.open("Tests/images/input_bw_one_band.fpx") as im:
14+
assert im.mode == "L"
15+
assert im.size == (70, 46)
16+
assert im.format == "FPX"
17+
18+
assert_image_equal_tofile(im, "Tests/images/input_bw_one_band.png")
19+
20+
1021
def test_invalid_file():
1122
# Test an invalid OLE file
1223
invalid_file = "Tests/images/flower.jpg"

src/PIL/FpxImagePlugin.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,16 @@ def _open_subimage(self, index=1, subimage=0):
154154

155155
for i in range(0, len(s), length):
156156

157+
x1 = min(xsize, x + xtile)
158+
y1 = min(ysize, y + ytile)
159+
157160
compression = i32(s, i + 8)
158161

159162
if compression == 0:
160163
self.tile.append(
161164
(
162165
"raw",
163-
(x, y, x + xtile, y + ytile),
166+
(x, y, x1, y1),
164167
i32(s, i) + 28,
165168
(self.rawmode,),
166169
)
@@ -172,7 +175,7 @@ def _open_subimage(self, index=1, subimage=0):
172175
self.tile.append(
173176
(
174177
"fill",
175-
(x, y, x + xtile, y + ytile),
178+
(x, y, x1, y1),
176179
i32(s, i) + 28,
177180
(self.rawmode, s[12:16]),
178181
)
@@ -201,7 +204,7 @@ def _open_subimage(self, index=1, subimage=0):
201204
self.tile.append(
202205
(
203206
"jpeg",
204-
(x, y, x + xtile, y + ytile),
207+
(x, y, x1, y1),
205208
i32(s, i) + 28,
206209
(rawmode, jpegmode),
207210
)

0 commit comments

Comments
 (0)