{"record":{"id":"759304f7e9b7f8d6","repo":"iBotPeaches/Apktool","slug":"unexpected-eof-while-skipping-chunk","errorCode":null,"errorMessage":"Unexpected EOF while skipping chunk.","messagePattern":"Unexpected EOF while skipping chunk\\.","errorType":"exception","errorClass":"EOFException","httpStatus":null,"severity":"critical","filePath":"brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResChunkPullParser.java","lineNumber":165,"sourceCode":"        }\n    }\n\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            }","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/iBotPeaches/Apktool/blob/79b63384d7d7e22917e6ea8b453272da7012515b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResChunkPullParser.java#L147-L183","documentation":"Thrown by ResChunkPullParser.skipChunk() when the underlying stream raises EOFException while skipping to the chunk's declared end. The chunk header promised more bytes than the stream actually contains, so the file is truncated relative to its own metadata. It is a hard signal that the binary resource file (resources.arsc, binary XML, etc.) is cut short.","triggerScenarios":"An APK truncated by an interrupted download or partial copy; a resources.arsc whose final chunk declares a size extending past the actual file; reading from a ZipRODirectory entry whose compressed data is cut off; memory-truncated streams in tests.","commonSituations":"Decoding an APK that failed to download completely; files extracted with a tool that stopped on a zip error; APKs served over flaky CI artifact storage; zip entries with bad CRC trimmed by 'repair' tools.","solutions":["Verify the APK integrity first: re-download or re-copy the file and check its zip CRCs (e.g. unzip -t app.apk).","Compare file length against the chunk's declared end (chunkStart() + chunkSize()) before skipping; if it exceeds the file size, reject the file as truncated.","If you must proceed, catch EOFException and treat the resource file as broken rather than retrying (apktool's --keep-broken-resources flag relaxes some of this during decode)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Before parsing, check the file is at least as long as the chunk claims\nlong chunkEnd = parser.chunkStart() + parser.chunkSize();\nif (chunkEnd > fileSize) {\n    throw new IOException(\"Truncated file: chunk ends at \" + chunkEnd + \" but file is \" + fileSize);\n}","typeGuard":null,"tryCatchPattern":"try {\n    parser.skipChunk();\n} catch (EOFException ex) {\n    // \"Unexpected EOF while skipping chunk.\" -> file truncated; mark resource as broken, do not retry\n    markResourceBroken();\n}","preventionTips":["Verify APK integrity (unzip -t / CRC check) before decoding","Re-download partially transferred files instead of parsing them","Treat EOF during skip as terminal for that file, not a retryable condition"],"tags":["android","apktool","binary-parsing","truncated-file","eof"],"backgroundTag":null,"analyzedSha":"79b63384d7d7e22917e6ea8b453272da7012515b","analyzedAt":"2026-08-14T10:43:28.812Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}