{"record":{"id":"97e9b62ae16b2bba","repo":"MuntashirAkon/AppManager","slug":"value-value-is-too-large-for-length-byte-field","errorCode":null,"errorMessage":"Value ${value} is too large for ${length} byte field.","messagePattern":"Value (.+?) is too large for (.+?) byte field\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java","lineNumber":509,"sourceCode":"\n        if (length < 9) {\n            formatLongBinary(value, buf, offset, length, negative);\n        } else {\n            formatBigIntegerBinary(value, buf, offset, length, negative);\n        }\n\n        buf[offset] = (byte) (negative ? 0xff : 0x80);\n        return offset + length;\n    }\n\n    private static void formatLongBinary(final long value, final byte[] buf,\n                                         final int offset, final int length,\n                                         final boolean negative) {\n        final int bits = (length - 1) * 8;\n        final long max = 1L << bits;\n        long val = Math.abs(value); // Long.MIN_VALUE stays Long.MIN_VALUE\n        if (val < 0 || val >= max) {\n            throw new IllegalArgumentException(\"Value \" + value +\n                \" is too large for \" + length + \" byte field.\");\n        }\n        if (negative) {\n            val ^= max - 1;\n            val++;\n            val |= 0xffL << bits;\n        }\n        for (int i = offset + length - 1; i >= offset; i--) {\n            buf[i] = (byte) val;\n            val >>= 8;\n        }\n    }\n\n    private static void formatBigIntegerBinary(final long value, final byte[] buf,\n                                               final int offset,\n                                               final int length,\n                                               final boolean negative) {\n        final BigInteger val = BigInteger.valueOf(value);","sourceCodeStart":491,"sourceCodeEnd":527,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java#L491-L527","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nTarArchiveOutputStream out = new TarArchiveOutputStream(fos); // BIGFILEMODE default, 4-byte binary\n// after\nTarArchiveOutputStream out = new TarArchiveOutputStream(fos, 1024, TarArchiveOutputStream.BIGFILEMODE_POSIX); // large values stored in PAX headers","handlingStrategy":"validation","validationCode":"int length = 8; // field length from header spec\nlong max = 1L << ((length - 1) * 8);\nif (value < 0 || value >= max) {\n    throw new IllegalArgumentException(\"Value \" + value + \" does not fit a \" + length + \"-byte tar field; use PAX/POSIX mode\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["tar","archive","numeric-overflow","header-field"],"backgroundTag":"value-out-of-range","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"}