Details
Description
When trying to read the following PDF document:
TIKA crashes for me with a java.lang.StackOverflowError, caused by a large number of recursion in:
at org.apache.tika.sax.ToXMLContentHandler$ElementInfo.getPrefix(ToXMLContentHandler.java:58)
For some reason, the Tika App doesn't exhibit this behavior, but the following MWE exposes the issue for me:
import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import org.apache.tika.metadata.Metadata; import org.apache.tika.parser.AutoDetectParser; import org.apache.tika.parser.ParseContext; import org.apache.tika.sax.ToHTMLContentHandler; public class test { public static void main(String [] args) throws Exception { String p = "/home/eggie/faulty_pdf_document.pdf"; FileInputStream input = new FileInputStream(new File(p)); AutoDetectParser tk = new AutoDetectParser(); ByteArrayOutputStream os = new ByteArrayOutputStream(); ToHTMLContentHandler handler = new ToHTMLContentHandler(os, "UTF-8"); ParseContext pc = new ParseContext(); System.out.println("Parsing"); tk.parse(input, handler, new Metadata(), pc); } }