{"record":{"id":"ce623fcbc50c8f08","repo":"iBotPeaches/Apktool","slug":"unexpected-chunk-ce623f","errorCode":null,"errorMessage":"Unexpected chunk: ","messagePattern":"Unexpected chunk: ","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"critical","filePath":"brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/BinaryXmlResourceParser.java","lineNumber":119,"sourceCode":"    public void setInput(Reader in) throws XmlPullParserException {\n        throw new XmlPullParserException(NOT_SUPPORTED);\n    }\n\n    @Override\n    public void setInput(InputStream inputStream, String inputEncoding) throws XmlPullParserException {\n        if (inputEncoding != null) {\n            throw new XmlPullParserException(NOT_SUPPORTED);\n        }\n\n        reset();\n        mIn = new BinaryDataInputStream(new BufferedInputStream(inputStream));\n        mParser = new ResChunkPullParser(mIn);\n        try {\n            if (!nextChunk()) {\n                throw new IOException(\"Input file is empty.\");\n            }\n            if (mParser.chunkType() != ResChunkHeader.RES_XML_TYPE) {\n                throw new IOException(\"Unexpected chunk: \" + mParser.chunkName() + \" (expected: RES_XML_TYPE)\");\n            }\n        } catch (IOException ex) {\n            mIn = null;\n            mParser = null;\n            throw new XmlPullParserException(\"Could not initialize parser.\", this, ex);\n        }\n\n        mParser = new ResChunkPullParser(mIn, mParser.dataSize());\n    }\n\n    @Override\n    public String getInputEncoding() {\n        return null;\n    }\n\n    @Override\n    public void defineEntityReplacementText(String entityName, String replacementText) throws XmlPullParserException {\n        throw new XmlPullParserException(NOT_SUPPORTED);","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/iBotPeaches/Apktool/blob/79b63384d7d7e22917e6ea8b453272da7012515b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/BinaryXmlResourceParser.java#L101-L137","documentation":"BinaryXmlResourceParser requires the first chunk of its input to be RES_XML_TYPE (0x0003). Any other leading chunk type throws this error, naming the offending chunk — the usual meaning is 'this file is not compiled binary XML'.","triggerScenarios":"Feeding the AXML parser a plain-text XML file (not compiled), an arsc (starts with 0x0002), or any non-AXML binary. Also fires on AXML files whose header was corrupted.","commonSituations":"Parsing XML that was never compiled with aapt/aapt2 (source res XML); mixed-up streams in extraction code; tools that store plain XML in APKs (some non-standard build chains); hex-corrupted manifest files.","solutions":["Check the first two bytes: 0x0003 = binary XML, 0x0002 = resource table, '<' (0x3C) = plain text XML.","If the file is plain text XML, parse it with a standard XmlPullParser instead — it never needed the binary parser.","If it should be AXML but isn't, the APK build/extract step is broken — recompile with aapt2 or re-extract.","For plain XML inside an APK from a non-standard packager, pre-detect the magic and route to the right parser."],"exampleFix":"// before\nparser.setInput(in, null); // throws if `in` is plain-text XML\n\n// after\nPushbackInputStream pb = new PushbackInputStream(in, 2);\nint b0 = pb.read(), b1 = pb.read();\nif (b0 == 0x03 && b1 == 0x00) {\n    pb.unread(b1); pb.unread(b0);\n    binParser.setInput(pb, null);\n} else {\n    pb.unread(b1); pb.unread(b0);\n    textParser.setInput(pb, null); // plain-text XML path\n}","handlingStrategy":"validation","validationCode":"byte[] magic = new byte[2];\ntry (InputStream s = new FileInputStream(xmlFile)) { s.read(magic); }\nboolean isBinaryXml = (magic[0] & 0xFF) == 0x03 && magic[1] == 0x00;\nboolean isPlainText = magic[0] == '<';\nif (!isBinaryXml) {\n    // route to a standard text XmlPullParser if isPlainText, else reject\n}","typeGuard":null,"tryCatchPattern":"try {\n    binParser.setInput(in, null);\n} catch (XmlPullParserException e) {\n    if (String.valueOf(e.getCause()).contains(\"Unexpected chunk\")) {\n        // wrong parser for this file — check magic and reroute\n    }\n}","preventionTips":["Sniff first bytes to choose binary vs text parser.","Don't assume all XML inside an APK is compiled AXML."],"tags":["apktool","axml","parsing","file-format","xml"],"backgroundTag":null,"analyzedSha":"79b63384d7d7e22917e6ea8b453272da7012515b","analyzedAt":"2026-08-14T10:43:28.812Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}