Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

add a end condition to svgParser for wrong content (if parser choosen just by file extension)

reger7c82cd44155a
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());
+ }
+ }
}
}
}