incubator-stormcrawler icon indicating copy to clipboard operation
incubator-stormcrawler copied to clipboard

Tika's detector breaks mime type guessing

Open mvolikas opened this issue 1 year ago • 4 comments

Version

main branch

Describe what's wrong

Tika's detector (used by JsoupParserBolt) seems to treat every file as potentially being an archive file and then fails because it actually isn't. Related to https://issues.apache.org/jira/browse/TIKA-4469. Comment by @rzo1 in dev list:

In the end, we should not use Tika's Detector but a TikaInputStream instead like that: try (TikaInputStream tis = TikaInputStream.get(data)) { final Metadata metadata = new Metadata(); metadata.add(TikaCoreProperties.RESOURCE_NAME_KEY, file.getFileName()); final MediaType mediaType = MimeTypes.getDefaultMimeTypes().detect(tis, metadata);

Error message and/or stacktrace

Exception while guessing mimetype on https://apache.org/: org.apache.commons.compress.archivers.ArchiveException: No Archiver found for the stream signature

How to reproduce

Run a crawl with the single seed URL "https://apache.org/".

Additional context

No response

mvolikas avatar Sep 07 '25 14:09 mvolikas

The linked issue explains that Tika expects the most recent version of commons-compress, or at least whatever version we depended on in 3.2.2.

Commons-compress used to throw an ArchiverException, and Tika used to catch that specific exception. In the latest compress, ArchiverException began extending IOException. Tika simplified its catch to IOException. If there’s an older version of compress on the class path, you’ll get this problem.

If you back off to MimeTypes…detect(), you’ll miss all container detectors and only rely on magic bytes. For some use cases, this is sufficient, but it might cause surprises and certainly will lead to lower precision detection.

On Sun, Sep 7, 2025 at 10:21 AM Markos Volikas @.***> wrote:

mvolikas created an issue (apache/stormcrawler#1650) https://github.com/apache/stormcrawler/issues/1650 Version

main branch Describe what's wrong

Tika's detector (used by JsoupParserBolt https://github.com/apache/stormcrawler/blob/main/core/src/main/java/org/apache/stormcrawler/bolt/JSoupParserBolt.java#L500) seems to treat every file as potentially being an archive file and then fails because it actually isn't. Related to https://issues.apache.org/jira/browse/TIKA-4469. Comment by @rzo1 https://github.com/rzo1 in dev list:

In the end, we should not use Tika's Detector but a TikaInputStream instead like that: try (TikaInputStream tis = TikaInputStream.get(data)) { final Metadata metadata = new Metadata(); metadata.add(TikaCoreProperties.RESOURCE_NAME_KEY, file.getFileName()); final MediaType mediaType = MimeTypes.getDefaultMimeTypes().detect(tis, metadata);

Error message and/or stacktrace

Exception while guessing mimetype on https://apache.org/: org.apache.commons.compress.archivers.ArchiveException: No Archiver found for the stream signature

How to reproduce

Run a crawl with the single seed URL "https://apache.org/". Additional context

No response

— Reply to this email directly, view it on GitHub https://github.com/apache/stormcrawler/issues/1650, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTNNPTT6GU6GBO5HUTTSEL3RQ5M3AVCNFSM6AAAAACF3BVZDGVHI2DSMVQWIX3LMV43ASLTON2WKOZTGM4TCNRWHE3DCOA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

tballison avatar Sep 07 '25 14:09 tballison

Thanks @tballison for details. Think we need to investigate, which version is on the classpath.

rzo1 avatar Sep 07 '25 14:09 rzo1

It seems that version 1.26.2 is pulled by avro:

[INFO] --- dependency:3.8.1:tree (default-cli) @ stormcrawler-warc ---
[INFO] org.apache.stormcrawler:stormcrawler-warc:jar:3.4.1-SNAPSHOT
[INFO] +- org.apache.stormcrawler:stormcrawler-core:jar:3.4.1-SNAPSHOT:compile
[INFO] |  \- org.apache.tika:tika-core:jar:3.2.2:compile
[INFO] \- org.apache.storm:storm-hdfs:jar:2.8.2:compile
[INFO]    \- org.apache.avro:avro:jar:1.12.0:compile
[INFO]       \- org.apache.commons:commons-compress:jar:1.26.2:compile

mvolikas avatar Sep 07 '25 14:09 mvolikas

Storm 2.8.2 is on 1.27.1 - should be okay to manage on our side, I guess. At least worth a try.

rzo1 avatar Sep 07 '25 15:09 rzo1