{"record":{"id":"81db24b85049ceae","repo":"iBotPeaches/Apktool","slug":"unexpected-chunk","errorCode":null,"errorMessage":"Unexpected chunk: ","messagePattern":"Unexpected chunk: ","errorType":"exception","errorClass":"AndrolibException","httpStatus":null,"severity":"critical","filePath":"brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/BinaryResourceParser.java","lineNumber":132,"sourceCode":"    public void enableCollectFlagsOffsets() {\n        mEntrySpecFlagsOffsets = new ArrayList<>();\n    }\n\n    public Collection<Pair<Long, Integer>> getEntrySpecFlagsOffsets() {\n        return mEntrySpecFlagsOffsets;\n    }\n\n    public void parse(InputStream in) throws AndrolibException {\n        reset();\n        mIn = new BinaryDataInputStream(new BufferedInputStream(in));\n\n        ResChunkPullParser parser = new ResChunkPullParser(mIn);\n        try {\n            if (!nextChunk(parser)) {\n                throw new AndrolibException(\"Input file is empty.\");\n            }\n            if (parser.chunkType() != ResChunkHeader.RES_TABLE_TYPE) {\n                throw new AndrolibException(\"Unexpected chunk: \" + parser.chunkName() + \" (expected: RES_TABLE_TYPE)\");\n            }\n\n            parseTable(parser);\n\n            Log.d(TAG, \"End of chunks at 0x%08x\", mIn.position());\n\n            // We can't use remaining() here, the length of the main stream is unknown.\n            if (mIn.available() > 0) {\n                Log.d(TAG, \"Ignoring trailing data at 0x%08x.\", mIn.position());\n            }\n        } catch (IOException ex) {\n            throw new AndrolibException(\"Could not decode arsc file.\", ex);\n        }\n    }\n\n    public void reset() {\n        mIn = null;\n        mMissingEntrySpecs.clear();","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/iBotPeaches/Apktool/blob/79b63384d7d7e22917e6ea8b453272da7012515b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/BinaryResourceParser.java#L114-L150","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\ntry (InputStream in = zip.getInputStream(entry)) { parser.parse(in); }\n\n// after\ntry (InputStream in = zip.getInputStream(entry)) {\n    int lo = in.read(), hi = in.read();\n    int chunkType = (hi << 8) | lo;\n    if (chunkType != 0x0002) {\n        throw new IllegalArgumentException(\"Not an arsc file: first chunk type 0x\" + Integer.toHexString(chunkType));\n    }\n    parser.parse(new SequenceInputStream(new ByteArrayInputStream(new byte[]{(byte) lo, (byte) hi}), in));\n}","handlingStrategy":"validation","validationCode":"byte[] head = new byte[2];\ntry (InputStream s = new FileInputStream(arscFile)) {\n    if (s.read(head) != 2 || (head[0] & 0xFF) != 0x02 || head[1] != 0) {\n        throw new IllegalArgumentException(\"Not a resources.arsc: bad first chunk type\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    parser.parse(in);\n} catch (AndrolibException e) {\n    if (e.getMessage().startsWith(\"Unexpected chunk:\")) {\n        // wrong file routed to arsc parser — check first bytes 0x0002\n    }\n}","preventionTips":["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."],"tags":["apktool","arsc","parsing","file-format","corrupt-file"],"backgroundTag":null,"analyzedSha":"79b63384d7d7e22917e6ea8b453272da7012515b","analyzedAt":"2026-08-14T10:43:28.812Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}