{"record":{"id":"8494b512f8ead07d","repo":"MuntashirAkon/AppManager","slug":"failed-to-read-paxheader-value-should-end-with-a-newline","errorCode":null,"errorMessage":"Failed to read Paxheader.Value should end with a newline","messagePattern":"Failed to read Paxheader\\.Value should end with a newline","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java","lineNumber":725,"sourceCode":"                                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) {\n                                        // previous GNU.sparse.offset header but but no numBytes\n                                        sparseHeaders.add(new TarArchiveStructSparse(offset, 0));\n                                    }\n                                    offset = Long.valueOf(value);\n                                }\n\n                                // for 0.0 PAX Headers\n                                if (keyword.equals(\"GNU.sparse.numbytes\")) {\n                                    if (offset == null) {","sourceCodeStart":707,"sourceCodeEnd":743,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java#L707-L743","documentation":"Thrown by TarUtils.parsePaxHeaders when a PAX header value's last byte is not the required terminating newline ('\\n'). The PAX format mandates each record end with LF; its absence means malformed or corrupted header data.","triggerScenarios":"A PAX record whose value bytes were read fully but do not end with a newline; caused by hand-built PAX headers missing the trailing LF or corrupted data.","commonSituations":"Archives produced by non-conforming writers or string manipulation that trimmed the trailing newline (e.g. custom code doing trim() on header content), binary-transfer corruption.","solutions":["Fix the archive producer to terminate each PAX record value with '\\n'","Re-pack the archive using a standards-conforming tool (GNU tar, bsdtar)","If hand-writing PAX headers, append newline after every value: len \" key=value \\n\"","Catch IOException and reject the archive as malformed"],"exampleFix":"// before (custom pax record writer)\nout.write((record).getBytes(UTF_8)); // record lacks trailing \\n\n// after\nout.write((record + \"\\n\").getBytes(UTF_8));","handlingStrategy":"validation","validationCode":"// when producing pax records yourself:\nif (record.charAt(record.length() - 1) != '\\n') {\n    record = record + '\\n';\n}","typeGuard":null,"tryCatchPattern":"try {\n    // read tar\n} catch (IOException e) {\n    if (e.getMessage().contains(\"Value should end with a newline\")) {\n        throw new CorruptArchiveException(\"PAX header value missing LF terminator\", e);\n    }\n    throw e;\n}","preventionTips":["Always terminate PAX record values with '\\n' when generating archives","Don't trim()/strip() PAX header strings before writing","Re-pack suspect archives with GNU tar"],"tags":["tar","pax-header","malformed-data","format-validation"],"backgroundTag":"schema-validation-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"}