{"record":{"id":"91fcbf4d3ed78531","repo":"iBotPeaches/Apktool","slug":"invalid-chunk-header-type-0x-04x-headersize-s","errorCode":null,"errorMessage":"Invalid chunk header: type=0x%04x, headerSize=%s, size=%s","messagePattern":"Invalid chunk header: type=0x%04x, headerSize=(.+?), size=(.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"critical","filePath":"brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResChunkPullParser.java","lineNumber":134,"sourceCode":"        if (mChunkHeader != null) {\n            skipChunk();\n            mChunkHeader = null;\n        }\n\n        if (mIn.position() >= mOffset + mSize) {\n            // End of chunks due to size limit.\n            mChunkOffset = OFFSET_ENDED;\n            return false;\n        }\n\n        // Read the chunk header at the current position.\n        try {\n            mChunkOffset = mIn.position();\n            ResChunkHeader chunkHeader = ResChunkHeader.read(mIn);\n\n            if (chunkHeader.headerSize < ResChunkHeader.SIZE\n                    || chunkHeader.size < chunkHeader.headerSize) {\n                throw new IOException(\n                    String.format(\"Invalid chunk header: type=0x%04x, headerSize=%s, size=%s\",\n                        chunkHeader.type, chunkHeader.headerSize, chunkHeader.size));\n            }\n\n            mChunkHeader = chunkHeader;\n            return true;\n        } catch (EOFException ignored) {\n            // End of chunks due to end of stream.\n            mChunkOffset = OFFSET_ENDED;\n            return false;\n        } catch (IOException ex) {\n            throw new IOException(\"Error while reading chunk header.\", ex);\n        }\n    }\n\n    public int skipChunk() throws IOException {\n        if (mChunkHeader == null) {\n            throw new IllegalStateException();","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/iBotPeaches/Apktool/blob/79b63384d7d7e22917e6ea8b453272da7012515b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResChunkPullParser.java#L116-L152","documentation":"ResChunkPullParser validates every chunk header: headerSize must be >= ResChunkHeader.SIZE (8) and the chunk's total size must be >= its header size. Violations mean the file's chunk framing is broken — the stream position can no longer be trusted — so an IOException with the offending type/headerSize/size values is thrown.","triggerScenarios":"Parsing (arsc or AXML) a file whose chunk headers were corrupted or crafted with impossible sizes — truncation at a chunk boundary, byte-level corruption, deliberate fuzzing, or a packer that rewrote headers incorrectly.","commonSituations":"Corrupt resource files from interrupted transfers; obfuscated arsc/AXML from protectors; fuzzing corpora; files patched in a hex editor with wrong length fields.","solutions":["Use the three reported values (type, headerSize, size) to locate the bad chunk in a hex dump — headerSize must be >= 8 and size >= headerSize.","Re-obtain the file/APK from a trusted source and compare checksums.","Validate with aapt2/apkanalyzer; if they also fail, the file itself is broken.","For packer-mangled files, find an unprotected build — header repair is rarely worth it."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"ByteBuffer buf = ByteBuffer.wrap(data).order(ByteOrder.LITTLE_ENDIAN);\nwhile (buf.remaining() >= 8) {\n    int type = buf.getShort() & 0xFFFF;\n    int headerSize = buf.getShort() & 0xFFFF;\n    int size = buf.getInt();\n    if (headerSize < 8 || size < headerSize || size > buf.remaining()) {\n        throw new IOException(String.format(\"Bad chunk 0x%04x at 0x%x\", type, buf.position() - 8));\n    }\n    buf.position(buf.position() + size - 8);\n}","typeGuard":null,"tryCatchPattern":"try {\n    parser.parse(in);\n} catch (IOException e) {\n    if (e.getMessage().contains(\"Invalid chunk header\")) {\n        // structural corruption — reject file, re-obtain artifact\n    }\n}","preventionTips":["Checksum files after transfer before parsing.","Pre-validate chunk framing when accepting files from untrusted sources.","Treat header anomalies as corruption, never skip-and-continue."],"tags":["apktool","chunk-header","parsing","corrupt-file","binary-format"],"backgroundTag":null,"analyzedSha":"79b63384d7d7e22917e6ea8b453272da7012515b","analyzedAt":"2026-08-14T10:43:28.812Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}