Copilot commented on code in PR #2865:
URL: https://github.com/apache/tika/pull/2865#discussion_r3351518643


##########
tika-parsers/tika-parsers-standard/tika-parsers-standard-integration-tests/src/test/java/org/apache/tika/parser/AndroidBinaryXMLTest.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import java.io.ByteArrayOutputStream;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+import java.util.zip.ZipEntry;
+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.Metadata;
+import org.apache.tika.metadata.TikaCoreProperties;
+
+/**
+ * Android Binary XML (AXML) is the compiled binary form of 
AndroidManifest.xml and the
+ * res/*.xml resources packed inside an APK. Those entries keep a .xml 
extension and live
+ * inside the (zip) APK, so before TIKA-4747 the *.xml glob caused them to be 
detected as
+ * application/xml and handed to the XML parser, which failed on the binary 
header with
+ * "Invalid byte 1 of 1-byte UTF-8 sequence". This was a large source of 
exceptions in
+ * regression runs over APK-heavy corpora.
+ *
+ * <p>Real corpus APKs can't be committed, so this builds an equivalent zip in 
memory:
+ * two compiled (AXML) entries plus one genuine text-XML entry under assets/ 
as a control,
+ * and asserts the AXML entries are detected as application/vnd.android.axml 
and produce no
+ * exception, while the text-XML entry is still application/xml.
+ */
+public class AndroidBinaryXMLTest extends TikaTest {
+
+    private static final String AXML = "application/vnd.android.axml";
+
+    /**
+     * Minimal but structurally-plausible Android Binary XML header:
+     * ResChunk_header {type=RES_XML_TYPE(0x0003), headerSize=0x0008, 
size=&lt;total&gt;}
+     * followed by a zeroed ResStringPool_header. Only the leading 4 bytes 
(0x00080003 LE)
+     * are the detection signature; the following 4 bytes are the per-file 
size.
+     */
+    private static byte[] axmlBytes() {
+        ByteBuffer bb = ByteBuffer.allocate(64).order(ByteOrder.LITTLE_ENDIAN);
+        bb.putShort((short) 0x0003);   // RES_XML_TYPE
+        bb.putShort((short) 0x0008);   // headerSize
+        bb.putInt(64);                 // total chunk size == file length
+        bb.putShort((short) 0x0001);   // RES_STRING_POOL_TYPE
+        bb.putShort((short) 0x001C);   // headerSize
+        bb.putInt(0x0000003C);         // string pool chunk size

Review Comment:
   In axmlBytes(), the chunk sizes are internally inconsistent: the top-level 
XML chunk declares a total size of 64 bytes, but the nested string pool chunk 
declares a size of 0x3C (60) bytes starting at offset 8, which would extend 
past EOF (8 + 60 = 68). This makes the fixture less structurally plausible and 
could start failing if an AXML-aware parser is introduced later.



-- 
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