mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
Limit tile size to avoid extending outside image
This commit is contained in:
parent
e80ddfd2b6
commit
4d6e5a0d09
BIN
Tests/images/input_bw_one_band.fpx
Normal file
BIN
Tests/images/input_bw_one_band.fpx
Normal file
Binary file not shown.
BIN
Tests/images/input_bw_one_band.png
Normal file
BIN
Tests/images/input_bw_one_band.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 477 B |
|
@ -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"
|
||||||
|
|
|
@ -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),
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user