Handle some invalid SVG images

Fix #986
This commit is contained in:
Julien Duponchelle 2017-04-24 17:31:20 +02:00
parent 78e030b7ab
commit c9ceeee9de
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8

View File

@ -17,7 +17,7 @@
import io import io
import struct import struct
from xml.etree.ElementTree import ElementTree from xml.etree.ElementTree import ElementTree, ParseError
def get_size(data, default_width=0, default_height=0): def get_size(data, default_width=0, default_height=0):
@ -95,7 +95,11 @@ def get_size(data, default_width=0, default_height=0):
filetype = "svg" filetype = "svg"
fhandle = io.BytesIO(data) fhandle = io.BytesIO(data)
tree = ElementTree() tree = ElementTree()
tree.parse(fhandle) try:
tree.parse(fhandle)
except ParseError:
raise ValueError("Invalid SVG file")
root = tree.getroot() root = tree.getroot()
try: try: