MuntashirAkon/AppManager · error · IllegalArgumentException
Value is too large for byte field.
Error message
Value ${value} is too large for ${length} byte field. What it means
Thrown by TarUtils.formatLongBinary when a numeric value cannot fit into a fixed-length TAR header field written in base-256 (binary) encoding. The field has one bit reserved for sign, so only (length-1)*8 bits are usable; values >= 2^((length-1)*8) cannot be represented. This is a hard limit of the TAR header layout, not a bug.
Solutions
- Ensure the value fits the field: use POSIX/PAX (TarArchiveOutputStream with BIGFILEMODE POSIX) so large sizes go to pax headers instead of binary fields
- Verify the file/entry size before writing: reject or split entries whose size >= 2^((length-1)*8)
- Check that you are not manually calling formatLongOctalOrBinaryBytes with a too-short length; pass the full field length from the header spec
- Catch IllegalArgumentException and surface a clear 'entry too large for selected tar format' message
Example fix
// before TarArchiveOutputStream out = new TarArchiveOutputStream(fos); // BIGFILEMODE default, 4-byte binary // after TarArchiveOutputStream out = new TarArchiveOutputStream(fos, 1024, TarArchiveOutputStream.BIGFILEMODE_POSIX); // large values stored in PAX headers
Defensive patterns
Strategy: validation
Validate before calling
int length = 8; // field length from header spec
long max = 1L << ((length - 1) * 8);
if (value < 0 || value >= max) {
throw new IllegalArgumentException("Value " + value + " does not fit a " + length + "-byte tar field; use PAX/POSIX mode");
} Prevention
- Use TarArchiveOutputStream BIGFILEMODE_POSIX for archives with large entries
- Check entry sizes against the format's field limits before putArchiveEntry
- Avoid hand-writing header fields; let commons-compress format them
When it happens
Trigger: Calling TarArchiveOutputStream.putArchiveEntry / closeArchiveEntry with an entry size, or any header numeric field, that when formatted via formatLongOctalOrBinaryBytes exceeds max = 1L << ((length-1)*8) for the chosen field length.
Common situations: Writing tar entries larger than 8 GiB with a 4-byte binary field, or restoring headers with truncated field lengths; creating archives with GNU big-number fields mis-sized by older tooling; Long.MIN_VALUE edge case where Math.abs overflows negative.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- APK files backup is requested but no APK files have been…
- APK files backup is requested but no APK files have been…
- ' ' is too big ( > ).
- ' ' is too long ( > bytes)
- Major device number is out of range: + devNo
AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12).
Data as JSON: /api/errors/97e9b62ae16b2bba.
Report an issue: GitHub.
Appendix: source
Thrown at app/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java:509
if (length < 9) {
formatLongBinary(value, buf, offset, length, negative);
} else {
formatBigIntegerBinary(value, buf, offset, length, negative);
}
buf[offset] = (byte) (negative ? 0xff : 0x80);
return offset + length;
}
private static void formatLongBinary(final long value, final byte[] buf,
final int offset, final int length,
final boolean negative) {
final int bits = (length - 1) * 8;
final long max = 1L << bits;
long val = Math.abs(value); // Long.MIN_VALUE stays Long.MIN_VALUE
if (val < 0 || val >= max) {
throw new IllegalArgumentException("Value " + value +
" is too large for " + length + " byte field.");
}
if (negative) {
val ^= max - 1;
val++;
val |= 0xffL << bits;
}
for (int i = offset + length - 1; i >= offset; i--) {
buf[i] = (byte) val;
val >>= 8;
}
}
private static void formatBigIntegerBinary(final long value, final byte[] buf,
final int offset,
final int length,
final boolean negative) {
final BigInteger val = BigInteger.valueOf(value);View on GitHub (pinned to 0152f468fc)