{"record":{"id":"8042f1c5f60c0f53","repo":"MuntashirAkon/AppManager","slug":"can-t-read-more-than-eight-bytes-into-a-long-value","errorCode":null,"errorMessage":"Can't read more than eight bytes into a long value","messagePattern":"Can't read more than eight bytes into a long value","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/org/apache/commons/compress/utils/ByteUtils.java","lineNumber":251,"sourceCode":"\n    /**\n     * {@link ByteConsumer} based on {@link OutputStream}.\n     * @since 1.14\n     */\n    public static class OutputStreamByteConsumer implements ByteConsumer {\n        private final OutputStream os;\n        public OutputStreamByteConsumer(final OutputStream os) {\n            this.os = os;\n        }\n        @Override\n        public void accept(final int b) throws IOException {\n            os.write(b);\n        }\n    }\n\n    private static void checkReadLength(final int length) {\n        if (length > 8) {\n            throw new IllegalArgumentException(\"Can't read more than eight bytes into a long value\");\n        }\n    }\n}","sourceCodeStart":233,"sourceCodeEnd":254,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/org/apache/commons/compress/utils/ByteUtils.java#L233-L254","documentation":"ByteUtils.checkReadLength is the guard used by every fromLittleEndian overload: since the result is accumulated into a Java long (64-bit), reading more than 8 bytes cannot be represented, so any length > 8 throws IllegalArgumentException immediately.","triggerScenarios":"Calling any ByteUtils.fromLittleEndian(...) with length > 8, e.g. trying to decode 16-byte UUIDs or long hashes in one call.","commonSituations":"Misunderstanding the API as supporting arbitrary-length integer reads; passing an unvalidated field width from a file format; assuming BigInteger-style semantics.","solutions":["Split reads larger than 8 bytes into multiple <=8-byte fromLittleEndian calls and combine (e.g. low/high longs)","Use BigInteger or a byte[]-based parser for values wider than 64 bits","Clamp/validate length before the call"],"exampleFix":"// before\nlong v = ByteUtils.fromLittleEndian(in, 16); // IllegalArgumentException\n// after\nlong lo = ByteUtils.fromLittleEndian(in, 8);\nlong hi = ByteUtils.fromLittleEndian(in, 8);\nBigInteger v = BigInteger.valueOf(hi).shiftLeft(64).add(BigInteger.valueOf(lo));","handlingStrategy":"validation","validationCode":"if (length > 8) throw new IllegalArgumentException(\"cannot read \" + length + \" bytes into a long; use <= 8 or BigInteger\");","typeGuard":null,"tryCatchPattern":"try { long v = ByteUtils.fromLittleEndian(in, length); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"eight bytes\")) { /* switch to BigInteger path */ } else throw e; }","preventionTips":["Remember fromLittleEndian targets a long: max 8 bytes","Route >64-bit fields through BigInteger or multi-read code paths","Clamp or assert field widths when loading format definitions"],"tags":["argument-validation","byte-utils","little-endian"],"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"}