From: johanengelen Date: Sat, 12 Jul 2008 14:28:25 +0000 (+0000) Subject: Don't crash on path parse error. Truncate the path data up to where it is valid. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=8033a869734919c5dc5c66021d883e7070ebfb3a;p=inkscape.git Don't crash on path parse error. Truncate the path data up to where it is valid. For now shows unsafe debug message about where the path was truncated. --- diff --git a/src/svg/svg-path.cpp b/src/svg/svg-path.cpp index 1ab70d101..3deb6105c 100644 --- a/src/svg/svg-path.cpp +++ b/src/svg/svg-path.cpp @@ -36,6 +36,7 @@ #include "libnr/n-art-bpath.h" #include "gnome-canvas-bpath-util.h" +#include "svg/svg.h" #include "svg/path-string.h" #include <2geom/pathvector.h> @@ -674,20 +675,28 @@ NArtBpath *sp_svg_read_path(gchar const *str) return bpath; } +/* + * Parses the path in str. When an error is found in the pathstring, this method + * returns a truncated path up to where the error was found in the pathstring. + * Returns an empty PathVector when str==NULL + */ Geom::PathVector sp_svg_read_pathv(char const * str) { - std::vector pathv; + Geom::PathVector pathv; if (!str) return pathv; // return empty pathvector when str == NULL + + typedef std::back_insert_iterator Inserter; + Inserter iter(pathv); + Geom::SVGPathGenerator generator(iter); + try { - pathv = Geom::parse_svg_path(str); + Geom::parse_svg_path(str, generator); } catch (Geom::SVGPathParseError e) { - g_warning("SVGPathParseError: %s", e.what()); - g_warning("svgd str: %s", str); - throw Geom::SVGPathParseError(); // rethrow, maybe not necessary, can instead return empty path? - return std::vector(); + generator.finish(); + g_warning("Malformed SVG path, truncated path up to where error was found.\n Input path=\"%s\"\n Parsed path=\"%s\"", str, sp_svg_write_path(pathv)); } return pathv;