{"record":{"id":"db2e1e7fa09302d2","repo":"iBotPeaches/Apktool","slug":"error-while-skipping-chunk","errorCode":null,"errorMessage":"Error while skipping chunk.","messagePattern":"Error while skipping chunk\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResChunkPullParser.java","lineNumber":167,"sourceCode":"\n    public int skipChunk() throws IOException {\n        if (mChunkHeader == null) {\n            throw new IllegalStateException();\n        }\n        try {\n            long position = mIn.position();\n            long chunkEnd = chunkEnd();\n            if (position == chunkEnd) {\n                return 0;\n            }\n            if (position > chunkEnd) {\n                throw new IOException(\"Stream advanced past chunk end.\");\n            }\n            return mIn.skipBytes((int) (chunkEnd - position));\n        } 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) {","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/iBotPeaches/Apktool/blob/79b63384d7d7e22917e6ea8b453272da7012515b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResChunkPullParser.java#L149-L185","documentation":"Generic wrapper thrown by ResChunkPullParser.skipChunk() for any IOException raised while skipping bytes to the chunk end that is not an EOFException. It preserves the original exception as the cause. Because the sibling 'Stream advanced past chunk end.' throw at ResChunkPullParser.java:161 sits inside this same try block, that error also surfaces wrapped here, with its message visible only via getCause().","triggerScenarios":"Any I/O failure inside mIn.skipBytes(): position > chunkEnd (the wrapped error 40), closed underlying stream, disk read errors on an extracted temp file, or a defective zip entry stream.","commonSituations":"Decoding corrupt or obfuscated APKs; streams closed early by another component; nested parsers reading more than the chunk allowed; filesystem issues on the temp extraction directory.","solutions":["Inspect ex.getCause(): if it is 'Stream advanced past chunk end.', a nested read consumed too much or the chunk size field is wrong; if EOF, the file is truncated.","Ensure nothing else closes or reads the BinaryDataInputStream while the parser owns it.","Validate chunk sizes against the real file length before parsing chunks you do not trust.","Treat unrecoverable cases as 'broken resource file' and skip that file with a warning, mirroring apktool's keep-broken-resources behavior."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    parser.skipChunk();\n} catch (IOException ex) {\n    Throwable cause = ex.getCause();\n    if (cause instanceof EOFException) { /* truncated file */ }\n    else if (cause != null && cause.getMessage().contains(\"Stream advanced past chunk end\")) { /* overrun bug or bad size field */ }\n    else { /* genuine I/O failure on backing store */ }\n}","preventionTips":["Always inspect getCause() on this wrapper before choosing a remedy","Keep exclusive ownership of the input stream during parsing","Log chunk type/offset (chunkName(), chunkStart()) when the error fires to locate the bad chunk"],"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"}