MuntashirAkon/AppManager · error · IOException

Record to write has length '${record.length}' which is not t

Error message

Record to write has length '${record.length}' which is not the record size of '${RECORD_SIZE}'

What it means

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.

Source

Thrown at app/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java:562

    }

    @Override
    public ArchiveEntry createArchiveEntry(final File inputPath, final String entryName, final LinkOption... options) throws IOException, ErrnoException {
        if (finished) {
            throw new IOException("Stream has already been finished");
        }
        return new TarArchiveEntry(inputPath, entryName);
    }

    /**
     * Write an archive record to the archive.
     *
     * @param record The record data to write to the archive.
     * @throws IOException on error
     */
    private void writeRecord(final byte[] record) throws IOException {
        if (record.length != RECORD_SIZE) {
            throw new IOException("Record to write has length '"
                + record.length
                + "' which is not the record size of '"
                + RECORD_SIZE + "'");
        }

        out.write(record);
        recordsWritten++;
    }

    private void padAsNeeded() throws IOException {
        final int start = recordsWritten % recordsPerBlock;
        if (start != 0) {
            for (int i = start; i < recordsPerBlock; i++) {
                writeEOFRecord();
            }
        }
    }

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Verify you are using an unmodified, consistent version of commons-compress (single jar version on the classpath, no shadowed classes).
  2. If you patched the library, ensure all record-building code pads buffers to exactly 512 bytes.
  3. Report to the library maintainers with a reproducing entry name/size if it occurs with stock code (likely a PAX-header edge case).

Example fix

// before (patched code)
byte[] record = paxData; // arbitrary length
writeRecord(record);
// after
byte[] record = new byte[RECORD_SIZE];
System.arraycopy(paxData, 0, record, 0, paxData.length); // zero-padded
writeRecord(record);
Defensive patterns

Strategy: try-catch

Try / catch

try {
    tarOut.putArchiveEntry(entry);
    tarOut.write(data);
    tarOut.closeArchiveEntry();
} catch (IOException e) {
    if (e.getMessage() != null && e.getMessage().startsWith("Record to write has length")) {
        // internal corruption: validate library version / report upstream
        throw new IllegalStateException("commons-compress internal inconsistency", e);
    }
    throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12). Data as JSON: /api/errors/82c43a7a3d3c0a32. Report an issue: GitHub.