diff --git a/main/src/com/google/refine/importers/XmlImporter.java b/main/src/com/google/refine/importers/XmlImporter.java index 6219bbc59..5900de6fb 100644 --- a/main/src/com/google/refine/importers/XmlImporter.java +++ b/main/src/com/google/refine/importers/XmlImporter.java @@ -317,11 +317,16 @@ public class XmlImporter extends TreeImportingParserBase { return factory.createXMLStreamReader(wrapPrefixRemovingInputStream(inputStream)); } - final static private InputStream wrapPrefixRemovingInputStream(InputStream inputStream) throws IOException { + final static private InputStream wrapPrefixRemovingInputStream(InputStream inputStream) + throws XMLStreamException, IOException { PushbackInputStream pis = new PushbackInputStream(inputStream); int b; - while ((b = pis.read()) >= 0) { - if (b == '<') { + int count = 0; + while (count < 100 && (b = pis.read()) >= 0) { + if (++count > 100) { + throw new XMLStreamException( + "File starts with too much non-XML content to skip over"); + } else if (b == '<') { pis.unread(b); break; }