From 7c82cd44155aea035512f071436e676191000055 Mon Sep 17 00:00:00 2001 From: reger Date: Tue, 29 Sep 2015 22:57:33 +0200 Subject: [PATCH] add a end condition to svgParser for wrong content (if parser choosen just by file extension) --- source/net/yacy/document/parser/images/svgParser.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/source/net/yacy/document/parser/images/svgParser.java b/source/net/yacy/document/parser/images/svgParser.java index dda4ff7b5..1f2733247 100644 --- a/source/net/yacy/document/parser/images/svgParser.java +++ b/source/net/yacy/document/parser/images/svgParser.java @@ -155,6 +155,7 @@ public class svgParser extends AbstractParser implements Parser { private final StringBuilder buffer = new StringBuilder(); private boolean scrapeMetaData = false; // true if within metadata tag + private boolean svgStartTagFound = false; // switch to recognize start tag processing, to cancel parsing on wrong tag private String docTitle = null; // document level title private String docDescription = null; // document level description @@ -175,9 +176,10 @@ public class svgParser extends AbstractParser implements Parser { // not implemented yet TODO: interprete RDF content // may contain RDF + DC, DC, CC ... } else { - if (null != tag) { + if (tag != null) { switch (tag) { case "svg": + svgStartTagFound = true; imgHeight = atts.getValue("height"); imgWidth = atts.getValue("width"); break; @@ -190,6 +192,11 @@ public class svgParser extends AbstractParser implements Parser { case "path": case "rect": throw new SAXException("EOF svg Metadata", new EOFException()); + default : { // K.O. criteria, start tag is not svg, fail parser on none svg + if (!svgStartTagFound) { + throw new SAXException("not a svg file, start tag "+tag, new Failure()); + } + } } } }