[
https://issues.apache.org/jira/browse/TIKA-4785?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18095371#comment-18095371
]
ASF GitHub Bot commented on TIKA-4785:
--------------------------------------
tballison opened a new pull request, #2944:
URL: https://github.com/apache/tika/pull/2944
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
Thanks for your contribution to [Apache Tika](https://tika.apache.org/)!
Your help is appreciated!
Before opening the pull request, please verify that
* there is an open issue on the [Tika issue
tracker](https://issues.apache.org/jira/projects/TIKA) which describes the
problem or the improvement. We cannot accept pull requests without an issue
because the change wouldn't be listed in the release notes.
* the issue ID (`TIKA-XXXX`)
- is referenced in the title of the pull request
- and placed in front of your commit messages surrounded by square
brackets (`[TIKA-XXXX] Issue or pull request title`)
* commits are squashed into a single one (or few commits for larger changes)
* Tika is successfully built and unit tests pass by running `./mvnw clean
test`
* there should be no conflicts when merging the pull request branch into the
*recent* `main` branch. If there are conflicts, please try to rebase the pull
request branch on top of a freshly pulled `main` branch
* if you add new module that downstream users will depend upon add it to
relevant group in `tika-bom/pom.xml`.
We will be able to faster integrate your pull request if these conditions
are met. If you have any questions how to fix your problem or about using Tika
in general, please sign up for the [Tika mailing
list](http://tika.apache.org/mail-lists.html). Thanks!
> 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)