{"record":{"id":"a77807b5e3f83acf","repo":"MuntashirAkon/AppManager","slug":"failed-to-read-paxheader-expected-restlen-bytes-read-got","errorCode":null,"errorMessage":"Failed to read Paxheader. Expected ${restLen} bytes, read ${got}","messagePattern":"Failed to read Paxheader\\. Expected (.+?) bytes, read (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java","lineNumber":716,"sourceCode":"                        totalRead++;\n                        if (totalRead < 0 || (headerSize >= 0 && totalRead >= headerSize)) {\n                             break;\n                         }\n                        if (ch == '='){ // end of keyword\n                            final String keyword = coll.toString(CharsetNames.UTF_8);\n                            // Get rest of entry\n                            final int restLen = len - read;\n                            if (restLen <= 1) { // only NL\n                                headers.remove(keyword);\n                            } else if (headerSize >= 0 && restLen > headerSize - totalRead) {\n                                throw new IOException(\"Paxheader value size \" + restLen\n                                    + \" exceeds size of header record\");\n\n                            } else {\n                                final byte[] rest = new byte[restLen];\n                                final int got = IOUtils.readFully(inputStream, rest);\n                                if (got != restLen) {\n                                    throw new IOException(\"Failed to read \"\n                                            + \"Paxheader. Expected \"\n                                            + restLen\n                                            + \" bytes, read \"\n                                            + got);\n                                }\n                                totalRead += restLen;\n                                // Drop trailing NL\n                                if (rest[restLen - 1] != '\\n') {\n                                    throw new IOException(\"Failed to read Paxheader.\"\n                                       + \"Value should end with a newline\");\n                                }\n                                final String value = new String(rest, 0,\n                                        restLen - 1, StandardCharsets.UTF_8);\n                                headers.put(keyword, value);\n\n                                // for 0.0 PAX Headers\n                                if (keyword.equals(\"GNU.sparse.offset\")) {\n                                    if (offset != null) {","sourceCodeStart":698,"sourceCodeEnd":734,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java#L698-L734","documentation":"Thrown by TarUtils.parsePaxHeaders when IOUtils.readFully cannot read the declared restLen bytes of a PAX keyword's value from the stream, i.e. the stream hit EOF prematurely. The PAX record promised more data than the stream contains.","triggerScenarios":"Reading a TAR whose PAX header value length field is larger than the actual remaining stream bytes; happens on truncated downloads or when the underlying InputStream ends mid PAX record.","commonSituations":"Incomplete file downloads, archives cut off by interrupted transfers or partial uploads, reading from a closed/socket stream that ended early.","solutions":["Check the archive file size against the expected size and re-download if truncated","Validate the source stream isn't closed or failing upstream","Catch IOException and treat the archive as corrupt","Re-create the archive with a standard tar tool"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"long expectedSize = getExpectedArchiveSize();\nif (archiveFile.length() != expectedSize) {\n    throw new IOException(\"Archive truncated: \" + archiveFile.length() + \" of \" + expectedSize + \" bytes\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    // read tar\n} catch (IOException e) {\n    if (e.getMessage().startsWith(\"Failed to read Paxheader\")) {\n        throw new TruncatedArchiveException(\"Download incomplete\", e);\n    }\n    throw e;\n}","preventionTips":["Compare downloaded size against expected size / checksum before extraction","Use resumable, verified downloads for large archives","Keep the source stream open for the whole extraction"],"tags":["tar","pax-header","eof","truncated-stream"],"backgroundTag":"file-read-failed","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}