Skip to content

Commit

Permalink
Raise error when WMF inch is zero
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Dec 15, 2024
1 parent a7338f8 commit a11ed50
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Tests/test_file_wmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ def test_load() -> None:
assert im.load()[0, 0] == (255, 255, 255)


def test_load_zero_inch() -> None:
b = BytesIO(b"\xd7\xcd\xc6\x9a\x00\x00" + b"\x00" * 10)
with pytest.raises(ValueError):
with Image.open(b):
pass


def test_register_handler(tmp_path: Path) -> None:
class TestHandler(ImageFile.StubHandler):
methodCalled = False
Expand Down
3 changes: 3 additions & 0 deletions src/PIL/WmfImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ def _open(self) -> None:

# get units per inch
self._inch = word(s, 14)
if self._inch == 0:
msg = "Invalid inch"
raise ValueError(msg)

# get bounding box
x0 = short(s, 6)
Expand Down

0 comments on commit a11ed50

Please sign in to comment.