Skip to content

Commit bd946be

Browse files
radarhereeyedav
authored andcommitted
Raise ValueError when WMF inch is zero (python-pillow#8600)
Co-authored-by: Andrew Murray <[email protected]>
1 parent 759c303 commit bd946be

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

Tests/test_file_wmf.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ def test_load() -> None:
3535
assert im.load()[0, 0] == (255, 255, 255)
3636

3737

38+
def test_load_zero_inch() -> None:
39+
b = BytesIO(b"\xd7\xcd\xc6\x9a\x00\x00" + b"\x00" * 10)
40+
with pytest.raises(ValueError):
41+
with Image.open(b):
42+
pass
43+
44+
3845
def test_register_handler(tmp_path: Path) -> None:
3946
class TestHandler(ImageFile.StubHandler):
4047
methodCalled = False

src/PIL/WmfImagePlugin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ def _open(self) -> None:
9292

9393
# get units per inch
9494
self._inch = word(s, 14)
95+
if self._inch == 0:
96+
msg = "Invalid inch"
97+
raise ValueError(msg)
9598

9699
# get bounding box
97100
x0 = short(s, 6)

0 commit comments

Comments
 (0)