Copilot commented on code in PR #3094:
URL: https://github.com/apache/tika/pull/3094#discussion_r3886833989
##########
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-apple-module/src/main/java/org/apache/tika/parser/iwork/IWorkPackageParser.java:
##########
@@ -104,7 +130,7 @@ public void parse(TikaInputStream tis, ContentHandler
handler, Metadata metadata
entryStream.reset(); // 4096 fails on github
if (type != null) {
- XHTMLContentHandler xhtml = new XHTMLContentHandler(handler,
metadata, context);
+ xhtml = new XHTMLContentHandler(handler, metadata, context);
ContentHandler contentHandler;
switch (type) {
Review Comment:
`xhtml.startDocument()` is called inside the zip-entry loop, but
`xhtml.endDocument()` is now called only once after the loop. If more than one
content entry is encountered, this can result in multiple `startDocument()`
calls without matching `endDocument()` calls and also overwrites the `xhtml`
instance mid-parse. Consider creating the `XHTMLContentHandler` once and only
calling `startDocument()` once (on first detected content entry).
##########
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-apple-module/src/test/java/org/apache/tika/parser/iwork/iwana/IWork18ParserTest.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * 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.
+ */
+package org.apache.tika.parser.iwork.iwana;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipOutputStream;
+
+import org.junit.jupiter.api.Test;
+
+import org.apache.tika.TikaTest;
+import org.apache.tika.io.TikaInputStream;
+import org.apache.tika.metadata.HttpHeaders;
+import org.apache.tika.metadata.Metadata;
+import org.apache.tika.metadata.TikaCoreProperties;
+import org.apache.tika.parser.ParseContext;
+
+public class IWork18ParserTest extends TikaTest {
+
+ /**
+ * The package's preview.jpg is the document's THUMBNAIL embedded
+ * document. The test fixture was saved without one, so a preview is
+ * added to a copy of it.
+ */
+ @Test
+ public void testPreviewIsTheThumbnail() throws Exception {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ try (InputStream is =
getResourceAsStream("/test-documents/testKeynote2018.key");
+ ZipInputStream in = new ZipInputStream(is);
+ ZipOutputStream out = new ZipOutputStream(bos)) {
+ ZipEntry entry;
+ while ((entry = in.getNextEntry()) != null) {
+ out.putNextEntry(new ZipEntry(entry.getName()));
+ in.transferTo(out);
+ out.closeEntry();
+ }
+ out.putNextEntry(new ZipEntry("Presentation.key/preview.jpg"));
+ out.write(new byte[]{(byte) 0xFF, (byte) 0xD8, (byte) 0xFF, (byte)
0xD9});
+ out.closeEntry();
Review Comment:
The test writes a 4-byte "JPEG" (SOI + marker + EOI) into `preview.jpg`.
When parsed as `image/jpeg`, Tika's `JpegParser`/metadata-extractor expects a
structurally valid JPEG and may record a parser failure in the embedded
metadata (or fail if embedded exceptions aren’t caught). Generate a tiny valid
JPEG for the preview bytes to keep the test robust.
--
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]