[
https://issues.apache.org/jira/browse/TIKA-4785?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Tim Allison reassigned TIKA-4785:
---------------------------------
Assignee: Tim Allison
> Tika 3.3.0 Fails to Detect Media Type of Embedded Objects of LibreOffice Files
> ------------------------------------------------------------------------------
>
> Key: TIKA-4785
> URL: https://issues.apache.org/jira/browse/TIKA-4785
> Project: Tika
> Issue Type: Bug
> Components: tika-core
> Affects Versions: 3.3.0
> Environment: Java 21
> Reporter: Xiaohong Yang
> Assignee: Tim Allison
> Priority: Major
> Attachments: Program_and_Sample_Files.zip
>
>
> [^Program_and_Sample_Files.zip]
> We use Tika to extract embedded objects from LibreOffice files. We also use
> Tika to get the media type of the extracted objects. We encountered an issue
> in media detection in Tika 3.3.0 in the following method. Note that there is
> no issue with Tika 3.2.3. The Java version is 21.
>
> public void parseEmbedded(InputStream inputStream, ContentHandler
> contentHandler, Metadata metadata,
> boolean outputHtml) throws SAXException, IOException {
> String fullFileName =
> metadata.get(TikaCoreProperties.{_}RESOURCE_NAME_KEY{_});
> if (fullFileName == null) {
> fullFileName = "file" + count++;
> }
> if (config == null) {
> System.{_}out{_}.println("config is null");
> return;
> }
> MediaType contentType = config.getDetector().detect(inputStream,
> metadata);
> String tikaExtension = null;
> boolean hasExtension = fullFileName.indexOf('.') != -1;
> if (!hasExtension && contentType != null) {
> try {
> tikaExtension =
> config.getMimeRepository().forName(contentType.toString()).getExtension();
> } catch (Exception e) {
> System.{_}out{_}.println("Error with TIKA trying to find the
> content type of the file.");
> }
> }
> String[] fileNameSplit = fullFileName.split("/");
> String fileName = fileNameSplit[fileNameSplit.length - 1];
> File outputFile = new File(outputDir.toFile(),
> FilenameUtils.{_}normalize{_}(fileName));
> System.{_}out{_}.println("Extracting '" + fileName + " to " + outputFile);
> FileOutputStream os = null;
> try {
> os = new FileOutputStream(outputFile);
> if (inputStream instanceof TikaInputStream tin) {
> if (tin.getOpenContainer() instanceof DirectoryEntry) {
> try(POIFSFileSystem fs = new POIFSFileSystem()){
> copy((DirectoryEntry) tin.getOpenContainer(),
> fs.getRoot());
> fs.writeFilesystem(os);
> }
> } else {
> IOUtils.{_}copy{_}(inputStream, os);
> }
> } else {
> IOUtils.{_}copy{_}(inputStream, os);
> }
> } catch (Exception ex) {
> ex.printStackTrace();
> } finally {
> if (os != null) {
> os.flush();
> os.close();
> }
> }
> }
>
> The error happens at the following line:
> MediaType contentType = config.getDetector().detect(inputStream,
> metadata);
> And the error is as follows:
> org.apache.tika.exception.TikaException: TIKA-198: Illegal IOException from
> org.apache.tika.parser.pkg.PackageParser@32a68f4f
> at
> org.apache.tika.parser.CompositeParser.parse(CompositeParser.java:304)
> at
> org.apache.tika.parser.CompositeParser.parse(CompositeParser.java:298)
> at
> org.apache.tika.parser.AutoDetectParser.parse(AutoDetectParser.java:198)
> at
> xyang.tickets.tika.ExtractFromLibreOffice.process(ExtractFromLibreOffice.java:59)
> at
> xyang.tickets.tika.ExtractFromLibreOffice.main(ExtractFromLibreOffice.java:35)
> Caused by: java.io.IOException: mark/reset not supported
> at
> java.base/java.util.zip.InflaterInputStream.reset(InflaterInputStream.java:314)
> Caused by: java.io.IOException: mark/reset not supported
>
> at
> org.apache.tika.detect.microsoft.POIFSContainerDetector.isOleHeader(POIFSContainerDetector.java:679)
> at
> org.apache.tika.detect.microsoft.POIFSContainerDetector.detect(POIFSContainerDetector.java:612)
> at
> org.apache.tika.detect.CompositeDetector.detect(CompositeDetector.java:84)
> at
> xyang.tickets.tika.ExtractFromLibreOffice$FileEmbeddedDocumentExtractor.parseEmbedded(ExtractFromLibreOffice.java:79)
> at
> org.apache.tika.parser.pkg.PackageParser.parseZipEntry(PackageParser.java:444)
> at
> org.apache.tika.parser.pkg.PackageParser.parseZipFile(PackageParser.java:397)
> at
> org.apache.tika.parser.pkg.PackageParser._parse(PackageParser.java:277)
> at
> org.apache.tika.parser.pkg.PackageParser.parse(PackageParser.java:261)
> at
> org.apache.tika.parser.CompositeParser.parse(CompositeParser.java:298)
> ... 4 more
>
> Attached are 4 files:
> ExtractFromLibreOffice.java --- the standalone program
> tika-config.xml --- config file
> calc.sxc --- Sample file
> impress.sxi --- Sample file
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)