Skip to content

Make image format detection and SvgImageFile initialisation more robust #144

@zerolab

Description

@zerolab

https://pastebin.com/jNWdCZ2N

File "/usr/local/lib/python3.8/site-packages/willow/image.py", line 313, in __init__
cms-app-6b79f8884b-tmjzb cms-app     self.dom = ElementTree.parse(f)
cms-app-6b79f8884b-tmjzb cms-app   File "/usr/local/lib/python3.8/site-packages/defusedxml/ElementTree.py", line 130, in parse
cms-app-6b79f8884b-tmjzb cms-app     return _parse(source, parser)
cms-app-6b79f8884b-tmjzb cms-app   File "/usr/local/lib/python3.8/xml/etree/ElementTree.py", line 1202, in parse
cms-app-6b79f8884b-tmjzb cms-app     tree.parse(source, parser)
cms-app-6b79f8884b-tmjzb cms-app   File "/usr/local/lib/python3.8/xml/etree/ElementTree.py", line 601, in parse
cms-app-6b79f8884b-tmjzb cms-app     parser.feed(data)
cms-app-6b79f8884b-tmjzb cms-app   File "/usr/local/lib/python3.8/xml/etree/ElementTree.py", 

Update: the issue seems to be with

Willow/willow/image.py

Lines 82 to 99 in 830aa3d

def open(cls, f):
# Detect image format
image_format = filetype.guess_extension(f)
if image_format is None and cls.maybe_xml(f):
image_format = "svg"
# Find initial class
initial_class = INITIAL_IMAGE_CLASSES.get(image_format)
if not initial_class:
if image_format:
raise UnrecognisedImageFormatError(
f"Cannot load {image_format} images ({INITIAL_IMAGE_CLASSES!r})"
)
else:
raise UnrecognisedImageFormatError("Unknown image format")
return initial_class(f)
(and specifically

Willow/willow/image.py

Lines 86 to 87 in 830aa3d

if image_format is None and cls.maybe_xml(f):
image_format = "svg"
) where the user is uploading a PNG (allegedly)

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