Skip to content

Commit bcd559a

Browse files
committed
respond to copilot -- further fixes and undo copilot's proposal
1 parent 047fecf commit bcd559a

2 files changed

Lines changed: 16 additions & 14 deletions

File tree

tika-core/src/main/resources/org/apache/tika/mime/tika-mimetypes.xml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -356,15 +356,15 @@
356356
<acronym>AXML</acronym>
357357
<_comment>Android Binary XML</_comment>
358358
<tika:link>https://developer.android.com/guide/topics/manifest/manifest-intro</tika:link>
359-
<!-- Compiled binary form of AndroidManifest.xml and res/*.xml inside an APK.
360-
These carry a .xml extension and live inside a zip, so the *.xml glob would
361-
otherwise route them to application/xml and the XML parser, which fails on the
362-
binary header. Detect by the leading ResChunk_header: type=RES_XML_TYPE(0x0003)
363-
+ headerSize(0x0008) -> 0x00080003 little-endian. The following 4 bytes are the
364-
per-file chunk size, so the signature is only the first 4 bytes. Deliberately
365-
NOT a sub-class-of application/xml: it is not XML and must not reach an XML parser. -->
366-
<magic priority="50">
367-
<match value="0x03000800" type="string" offset="0"/>
359+
<!-- Compiled AndroidManifest.xml / res/*.xml inside an APK. The .xml extension would
360+
otherwise route it to the XML parser, which fails on the binary header. Signature:
361+
RES_XML_TYPE(0x0003)+headerSize(0x0008)=0x00080003 LE, plus RES_STRING_POOL_TYPE
362+
(0x0001) at offset 8 (the variable per-file size at offset 4 is skipped). Not a
363+
sub-class-of application/xml: must not reach an XML parser. -->
364+
<magic priority="50">
365+
<match value="0x03000800" type="string" offset="0">
366+
<match value="0x0001" type="little16" offset="8"/>
367+
</match>
368368
</magic>
369369
</mime-type>
370370
<mime-type type="application/x-tika-java-enterprise-archive">

tika-parsers/tika-parsers-standard/tika-parsers-standard-integration-tests/src/test/java/org/apache/tika/parser/AndroidBinaryXMLTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,18 @@ public class AndroidBinaryXMLTest extends TikaTest {
5252
private static final String AXML = "application/vnd.android.axml";
5353

5454
/**
55-
* Minimal but structurally-plausible Android Binary XML header:
56-
* ResChunk_header {type=RES_XML_TYPE(0x0003), headerSize=0x0008, size=&lt;total&gt;}
57-
* followed by a zeroed ResStringPool_header. Only the leading 4 bytes (0x00080003 LE)
58-
* are the detection signature; the following 4 bytes are the per-file size.
55+
* Minimal compiled-AXML header: a RES_XML_TYPE ResChunk_header plus the ResStringPool
56+
* chunk real AXML always carries. The magic matches 0x00080003 (LE) at offset 0 and the
57+
* string-pool type 0x0001 at offset 8, so both must be present.
5958
*/
6059
private static byte[] axmlBytes() {
6160
ByteBuffer bb = ByteBuffer.allocate(64).order(ByteOrder.LITTLE_ENDIAN);
6261
bb.putShort((short) 0x0003); // RES_XML_TYPE
6362
bb.putShort((short) 0x0008); // headerSize
64-
bb.putInt(0x00000038); // string pool chunk size
63+
bb.putInt(64); // total chunk size == file length (skipped by magic)
64+
bb.putShort((short) 0x0001); // RES_STRING_POOL_TYPE (checked at offset 8)
65+
bb.putShort((short) 0x001C); // string-pool headerSize
66+
bb.putInt(0x0000003C); // string-pool chunk size
6567
// remaining bytes (string/style counts, flags, offsets) left zero
6668
return bb.array();
6769
}

0 commit comments

Comments
 (0)