{"record":{"id":"d57ff6367a1cce5a","repo":"iBotPeaches/Apktool","slug":"error-while-skipping-chunk-header","errorCode":null,"errorMessage":"Error while skipping chunk header.","messagePattern":"Error while skipping chunk header\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResChunkPullParser.java","lineNumber":188,"sourceCode":"\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":170,"sourceCodeEnd":192,"githubUrl":"https://github.com/iBotPeaches/Apktool/blob/79b63384d7d7e22917e6ea8b453272da7012515b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResChunkPullParser.java#L170-L192","documentation":"Generic wrapper thrown by ResChunkPullParser.skipHeader() for non-EOF IOExceptions raised while skipping the header bytes; the original exception is attached as the cause. The 'Stream advanced past chunk header end.' throw at ResChunkPullParser.java:182 is inside the try, so it also surfaces wrapped here with its message only on the cause chain.","triggerScenarios":"position > headerEnd when skipHeader() is called (wrapped error 43); underlying stream already closed; I/O errors on the backing file or zip entry during the skip.","commonSituations":"Custom chunk-header reads followed by skipHeader(); sharing the input stream between components; corrupt APKs with rewritten headerSize fields.","solutions":["Unwrap ex.getCause() to distinguish 'advanced past header end' (logic error / bad headerSize) from genuine I/O failures.","Only call skipHeader() before any header consumption, once per chunk.","Keep exclusive ownership of the BinaryDataInputStream during parsing."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    parser.skipHeader();\n} catch (IOException ex) {\n    Throwable cause = ex.getCause();\n    if (cause != null && cause.getMessage().contains(\"chunk header end\")) {\n        // header was already consumed -> fix calling code\n    } else {\n        // I/O failure on backing stream\n    }\n}","preventionTips":["Unwrap the cause before deciding on a fix","Never interleave manual header reads with skipHeader()","Close streams only after the parser loop finishes"],"tags":["android","apktool","binary-parsing","io","wrapper-exception"],"backgroundTag":null,"analyzedSha":"79b63384d7d7e22917e6ea8b453272da7012515b","analyzedAt":"2026-08-14T10:43:28.812Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}