Skip to content

ZeroDivisionError occurs when calling Image.open #8597

@gabe-sherman

Description

@gabe-sherman

A ZeroDivisionError occurs at line 105 in WmfImagePlugin.py when the below code is run. A check to self._inch is missed, resulting in a ZeroDivisionError rather than an "Unsupported file format" message.

import PIL.Image as Im
import io

data = io.BytesIO(b'\xd7\xcd\xc6\x9a\x00\x00\xff\xff\xff\xff\x00\x00\x00<\x00\x00')
Im.open(data)

Version:

pip show pillow
Name: pillow
Version: 11.1.0.dev0

Trace:

Traceback (most recent call last):
  File "rep.py", line 5, in <module>
    Im.open(data)
  File "python3.9/site-packages/PIL/Image.py", line 3511, in open
    im = _open_core(
  File "python3.9/site-packages/PIL/Image.py", line 3494, in _open_core
    im = factory(fp, filename)
  File "python3.9/site-packages/PIL/ImageFile.py", line 144, in __init__
    self._open()
  File "python3.9/site-packages/PIL/WmfImagePlugin.py", line 105, in _open
    (x1 - x0) * self.info["dpi"] // self._inch,
ZeroDivisionError: integer division or modulo by zero

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions