iBotPeaches/Apktool · critical · AndrolibException
Unexpected chunk:
Error message
Unexpected chunk:
What it means
BinaryResourceParser.parse expects the first chunk of a resources.arsc stream to be RES_TABLE_TYPE (the resource table root, type 0x0002). Any other leading chunk type throws this error, naming the chunk that was found instead.
Source
Thrown at brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/BinaryResourceParser.java:132
public void enableCollectFlagsOffsets() {
mEntrySpecFlagsOffsets = new ArrayList<>();
}
public Collection<Pair<Long, Integer>> getEntrySpecFlagsOffsets() {
return mEntrySpecFlagsOffsets;
}
public void parse(InputStream in) throws AndrolibException {
reset();
mIn = new BinaryDataInputStream(new BufferedInputStream(in));
ResChunkPullParser parser = new ResChunkPullParser(mIn);
try {
if (!nextChunk(parser)) {
throw new AndrolibException("Input file is empty.");
}
if (parser.chunkType() != ResChunkHeader.RES_TABLE_TYPE) {
throw new AndrolibException("Unexpected chunk: " + parser.chunkName() + " (expected: RES_TABLE_TYPE)");
}
parseTable(parser);
Log.d(TAG, "End of chunks at 0x%08x", mIn.position());
// We can't use remaining() here, the length of the main stream is unknown.
if (mIn.available() > 0) {
Log.d(TAG, "Ignoring trailing data at 0x%08x.", mIn.position());
}
} catch (IOException ex) {
throw new AndrolibException("Could not decode arsc file.", ex);
}
}
public void reset() {
mIn = null;
mMissingEntrySpecs.clear();View on GitHub (pinned to 79b63384d7)
Solutions
- Confirm the file is really resources.arsc: first two bytes (little-endian) should be 0x0002; a binary XML starts with 0x0003.
- If parsing from a zip, make sure you opened the correct entry and that you are not passing a still-deflated stream (use ZipInputStream/ZipFile, not a raw FileInputStream on the APK).
- Re-obtain the APK from a trusted source — obfuscators/packers that reorder chunks make the arsc undecodable by this parser.
- Dump the first 16 bytes (`xxd resources.arsc | head -1`) and compare against the RES_TABLE_TYPE layout before debugging further.
Example fix
// before
try (InputStream in = zip.getInputStream(entry)) { parser.parse(in); }
// after
try (InputStream in = zip.getInputStream(entry)) {
int lo = in.read(), hi = in.read();
int chunkType = (hi << 8) | lo;
if (chunkType != 0x0002) {
throw new IllegalArgumentException("Not an arsc file: first chunk type 0x" + Integer.toHexString(chunkType));
}
parser.parse(new SequenceInputStream(new ByteArrayInputStream(new byte[]{(byte) lo, (byte) hi}), in));
} Defensive patterns
Strategy: validation
Validate before calling
byte[] head = new byte[2];
try (InputStream s = new FileInputStream(arscFile)) {
if (s.read(head) != 2 || (head[0] & 0xFF) != 0x02 || head[1] != 0) {
throw new IllegalArgumentException("Not a resources.arsc: bad first chunk type");
}
} Try / catch
try {
parser.parse(in);
} catch (AndrolibException e) {
if (e.getMessage().startsWith("Unexpected chunk:")) {
// wrong file routed to arsc parser — check first bytes 0x0002
}
} Prevention
- Sniff chunk-type magic (arsc=0x0002, AXML=0x0003) before choosing a parser.
- Always open resources from ZipFile/ZipInputStream entries, never raw file streams of the APK.
- Reject repackaged APKs from untrusted pipelines.
When it happens
Trigger: Passing a non-arsc file to the arsc parser: a binary XML file (AXML), a DEX, or an arsc whose header bytes are corrupted/byte-swapped. Also happens when the stream was double-compressed and is being read while still deflated.
Common situations: Misrouted file in a custom pipeline (parsing AndroidManifest.xml or a .dex with the arsc parser); resources.arsc obfuscated by packers that shuffle chunk order; wrong stream opened from a zip entry; endian/encoding transforms applied by a repackaging tool.
Related errors
- Input file is empty.
- Config size < 8
- Could not decode arsc file.
- Missing type string pool.
- Missing key string pool
AI-assisted analysis of iBotPeaches/Apktool@79b63384d7 (2026-08-14).
Data as JSON: /api/errors/81db24b85049ceae.
Report an issue: GitHub.