{"record":{"id":"82c43a7a3d3c0a32","repo":"MuntashirAkon/AppManager","slug":"record-to-write-has-length-record-length-which-is-not-the","errorCode":null,"errorMessage":"Record to write has length '${record.length}' which is not the record size of '${RECORD_SIZE}'","messagePattern":"Record to write has length '(.+?)' which is not the record size of '(.+?)'","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java","lineNumber":562,"sourceCode":"    }\n\n    @Override\n    public ArchiveEntry createArchiveEntry(final File inputPath, final String entryName, final LinkOption... options) throws IOException, ErrnoException {\n        if (finished) {\n            throw new IOException(\"Stream has already been finished\");\n        }\n        return new TarArchiveEntry(inputPath, entryName);\n    }\n\n    /**\n     * Write an archive record to the archive.\n     *\n     * @param record The record data to write to the archive.\n     * @throws IOException on error\n     */\n    private void writeRecord(final byte[] record) throws IOException {\n        if (record.length != RECORD_SIZE) {\n            throw new IOException(\"Record to write has length '\"\n                + record.length\n                + \"' which is not the record size of '\"\n                + RECORD_SIZE + \"'\");\n        }\n\n        out.write(record);\n        recordsWritten++;\n    }\n\n    private void padAsNeeded() throws IOException {\n        final int start = recordsWritten % recordsPerBlock;\n        if (start != 0) {\n            for (int i = start; i < recordsPerBlock; i++) {\n                writeEOFRecord();\n            }\n        }\n    }\n","sourceCodeStart":544,"sourceCodeEnd":580,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java#L544-L580","documentation":"writeRecord(byte[]) is an internal method that writes one 512-byte tar block (RECORD_SIZE) to the underlying stream. It validates the record's length and throws if it deviates, because tar archives are built from fixed-size blocks; a wrong-sized record would corrupt the block alignment of everything after it. Callers are putArchiveEntry (via padding/PAX header records) and writeEOFRecord.","triggerScenarios":"An internal caller passing a byte array whose length differs from 512 — e.g. a PAX header or long-name block padded incorrectly, or EOF record construction failing to produce exactly RECORD_SIZE bytes. Normal user code cannot call this private method directly; hitting it indicates an internal padding bug or a modified/forked build.","commonSituations":"Custom patches to the compress library altering header/PAX generation; corrupted library build (mixed versions of the jar); extremely large PAX headers where padding logic miscalculates block size.","solutions":["Verify you are using an unmodified, consistent version of commons-compress (single jar version on the classpath, no shadowed classes).","If you patched the library, ensure all record-building code pads buffers to exactly 512 bytes.","Report to the library maintainers with a reproducing entry name/size if it occurs with stock code (likely a PAX-header edge case)."],"exampleFix":"// before (patched code)\nbyte[] record = paxData; // arbitrary length\nwriteRecord(record);\n// after\nbyte[] record = new byte[RECORD_SIZE];\nSystem.arraycopy(paxData, 0, record, 0, paxData.length); // zero-padded\nwriteRecord(record);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    tarOut.putArchiveEntry(entry);\n    tarOut.write(data);\n    tarOut.closeArchiveEntry();\n} catch (IOException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Record to write has length\")) {\n        // internal corruption: validate library version / report upstream\n        throw new IllegalStateException(\"commons-compress internal inconsistency\", e);\n    }\n    throw e;\n}","preventionTips":["Pin a single, unpatched version of commons-compress on the classpath.","Avoid extremely large PAX header metadata (huge entry names/paths) that can stress header padding logic.","Report reproducible occurrences upstream rather than working around them."],"tags":["tar","archive","internal-invariant","io"],"backgroundTag":"internal-invariant-violation","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}