{"record":{"id":"b8199e2003a7a289","repo":"iBotPeaches/Apktool","slug":"stream-advanced-past-chunk-header-end","errorCode":null,"errorMessage":"Stream advanced past chunk header end.","messagePattern":"Stream advanced past chunk header end\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResChunkPullParser.java","lineNumber":182,"sourceCode":"        } catch (EOFException ignored) {\n            throw new EOFException(\"Unexpected EOF while skipping chunk.\");\n        } catch (IOException ex) {\n            throw new IOException(\"Error while skipping chunk.\", ex);\n        }\n    }\n\n    public int skipHeader() throws IOException {\n        if (mChunkHeader == null) {\n            throw new IllegalStateException();\n        }\n        try {\n            long position = mIn.position();\n            long headerEnd = headerEnd();\n            if (position == headerEnd) {\n                return 0;\n            }\n            if (position > headerEnd) {\n                throw new IOException(\"Stream advanced past chunk header end.\");\n            }\n            return mIn.skipBytes((int) (headerEnd - position));\n        } catch (EOFException ignored) {\n            throw new EOFException(\"Unexpected EOF while skipping chunk header.\");\n        } catch (IOException ex) {\n            throw new IOException(\"Error while skipping chunk header.\", ex);\n        }\n    }\n}\n","sourceCodeStart":164,"sourceCodeEnd":192,"githubUrl":"https://github.com/iBotPeaches/Apktool/blob/79b63384d7d7e22917e6ea8b453272da7012515b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResChunkPullParser.java#L164-L192","documentation":"Thrown by ResChunkPullParser.skipHeader() when the stream position is already past the chunk header's end (chunkOffset + header.headerSize). This means the caller consumed part or all of the header region before asking to skip it — the parser cannot skip backwards. Like error 40, this throw occurs inside the method's try block and is re-wrapped as 'Error while skipping chunk header.' (error 45) in practice.","triggerScenarios":"Reading header fields manually from parser.stream() and then calling skipHeader(); calling skipHeader() twice for the same chunk; a chunk header whose headerSize field is inconsistent with what was actually read.","commonSituations":"Custom parsers that inspect the raw header bytes (type, headerSize, size) directly instead of using the accessors (chunkType(), headerSize(), chunkSize()); obfuscated APKs with malformed headerSize values.","solutions":["Do not read header bytes from stream() yourself; use the parser's accessors and call skipHeader() exactly once per chunk.","Check in.position() < parser.headerEnd() before calling skipHeader().","Validate headerSize >= ResChunkHeader.SIZE (8) — next() already rejects headers smaller than that, so a smaller value indicates tampering."],"exampleFix":"// before\nint type = in.readShort(); // consumed part of the header\nparser.skipHeader();       // throws: position > headerEnd\n\n// after\nint type = parser.chunkType(); // accessor, no stream consumption\nparser.skipHeader();","handlingStrategy":"validation","validationCode":"// Only skip a header we have not started reading\nif (parser.isChunk() && parser.stream().position() < parser.chunkStart() + parser.headerSize()) {\n    parser.skipHeader();\n} else {\n    throw new IllegalStateException(\"Header already (partially) consumed\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    parser.skipHeader();\n} catch (IOException ex) {\n    // header overrun or I/O failure; check cause chain and abort chunk parsing\n}","preventionTips":["Use accessors chunkType()/headerSize()/chunkSize() instead of raw stream reads of the header","Call skipHeader() at most once per chunk, before any body reads","Validate headerSize >= 8 (ResChunkHeader.SIZE) when parsing untrusted files"],"tags":["android","apktool","binary-parsing","resource-table","corruption"],"backgroundTag":null,"analyzedSha":"79b63384d7d7e22917e6ea8b453272da7012515b","analyzedAt":"2026-08-14T10:43:28.812Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}