Skip to content

Raise ValueError for EMF files with a zero-sized frame - #10381

Merged
radarhere merged 2 commits into
python-pillow:mainfrom
arxhr007:emf-zero-frame
Nov 2, 2026
Merged

radarhere merged 2 commits into
python-pillow:mainfrom
arxhr007:emf-zero-frame

Conversation

@arxhr007

@arxhr007 arxhr007 commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Changes proposed in this pull request:

  • An EMF header whose frame has zero width or height made Image.open() raise ZeroDivisionError, because the dots per inch are calculated by dividing by the frame size:

    data = bytearray(open("Tests/images/drawing.emf", "rb").read())
    data[32:36] = data[24:28]  # frame right == frame left
    Image.open(io.BytesIO(data))  # ZeroDivisionError: float division by zero
  • Raise ValueError("Invalid frame") instead. This matches what the placeable WMF branch just above already does for a zero inch (test_load_zero_inch).

  • Added a test for a zero-width and a zero-height frame.

@radarhere
radarhere enabled auto-merge (squash) November 2, 2026 01:13
@radarhere
radarhere merged commit 584bbb8 into python-pillow:main Nov 2, 2026
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants