THausherr commented on code in PR #3094:
URL: https://github.com/apache/tika/pull/3094#discussion_r3887218267


##########
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-apple-module/src/main/java/org/apache/tika/parser/iwork/IWorkPackageParser.java:
##########
@@ -87,12 +91,41 @@ public Set<MediaType> getSupportedTypes(ParseContext 
context) {
         return supportedTypes;
     }
 
+    /**
+     * The document preview of an iWork '09 package.
+     */
+    public final static String IWORK_THUMBNAIL_ENTRY = 
"QuickLook/Thumbnail.jpg";
+
+    /**
+     * Bound on the preview held in memory until the content has been
+     * parsed; a real one is well under a megabyte.
+     */
+    private static final long MAX_THUMBNAIL_BYTES = 20 * 1024 * 1024;
+
     public void parse(TikaInputStream tis, ContentHandler handler, Metadata 
metadata,
                       ParseContext context) throws IOException, SAXException, 
TikaException {
         ZipArchiveInputStream zip = new ZipArchiveInputStream(tis);
         ZipArchiveEntry entry = zip.getNextEntry();
+        //the package is read as a stream, so the preview may come before the
+        //content: hold it back and emit it once the content is written, and
+        //only when the embedded document extractor wants it at all
+        EmbeddedDocumentExtractor extractor =
+                EmbeddedDocumentUtil.getEmbeddedDocumentExtractor(context);
+        Metadata thumbnailMetadata = null;
+        byte[] thumbnail = null;
+        XHTMLContentHandler xhtml = null;
 
         while (entry != null) {
+            if (IWORK_THUMBNAIL_ENTRY.equals(entry.getName()) && 
zip.canReadEntryData(entry)) {
+                thumbnailMetadata = thumbnailMetadata(context);
+                if (extractor.shouldParseEmbedded(thumbnailMetadata, context)) 
{
+                    thumbnail = IOUtils.toByteArray(
+                            BoundedInputStream.builder().setInputStream(zip)
+                                    .setMaxCount(MAX_THUMBNAIL_BYTES).get());

Review Comment:
   I agree, this would be weird, and the user should know about it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to