From c9ceeee9de2da1cb1c18ae2fef34703bf1c65113 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Mon, 24 Apr 2017 17:31:20 +0200 Subject: [PATCH] Handle some invalid SVG images Fix #986 --- gns3server/utils/picture.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gns3server/utils/picture.py b/gns3server/utils/picture.py index 50d17996..1ec072de 100644 --- a/gns3server/utils/picture.py +++ b/gns3server/utils/picture.py @@ -17,7 +17,7 @@ import io 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): @@ -95,7 +95,11 @@ def get_size(data, default_width=0, default_height=0): filetype = "svg" fhandle = io.BytesIO(data) tree = ElementTree() - tree.parse(fhandle) + try: + tree.parse(fhandle) + except ParseError: + raise ValueError("Invalid SVG file") + root = tree.getroot() try: