dschmidt commented on code in PR #3094:
URL: https://github.com/apache/tika/pull/3094#discussion_r3886948448
##########
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,34 @@ 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
+ byte[] thumbnail = null;
+ XHTMLContentHandler xhtml = null;
while (entry != null) {
+ if (IWORK_THUMBNAIL_ENTRY.equals(entry.getName()) &&
zip.canReadEntryData(entry)) {
+ thumbnail = IOUtils.toByteArray(
+ BoundedInputStream.builder().setInputStream(zip)
+ .setMaxCount(MAX_THUMBNAIL_BYTES).get());
+ entry = zip.getNextEntry();
+ continue;
+ }
Review Comment:
Fixed: the thumbnail's metadata is built first and the entry is only
buffered when shouldParseEmbedded says yes.
--
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]