MuntashirAkon/AppManager · error · IllegalArgumentException

Can't read more than eight bytes into a long value

Error message

Can't read more than eight bytes into a long value

What it means

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.

Solutions

  1. Split reads larger than 8 bytes into multiple <=8-byte fromLittleEndian calls and combine (e.g. low/high longs)
  2. Use BigInteger or a byte[]-based parser for values wider than 64 bits
  3. Clamp/validate length before the call

Example fix

// before
long v = ByteUtils.fromLittleEndian(in, 16); // IllegalArgumentException
// after
long lo = ByteUtils.fromLittleEndian(in, 8);
long hi = ByteUtils.fromLittleEndian(in, 8);
BigInteger v = BigInteger.valueOf(hi).shiftLeft(64).add(BigInteger.valueOf(lo));
Defensive patterns

Strategy: validation

Validate before calling

if (length > 8) throw new IllegalArgumentException("cannot read " + length + " bytes into a long; use <= 8 or BigInteger");

Try / catch

try { long v = ByteUtils.fromLittleEndian(in, length); } catch (IllegalArgumentException e) { if (e.getMessage().contains("eight bytes")) { /* switch to BigInteger path */ } else throw e; }

Prevention

When it happens

Trigger: Calling any ByteUtils.fromLittleEndian(...) with length > 8, e.g. trying to decode 16-byte UUIDs or long hashes in one call.

Common situations: Misunderstanding the API as supporting arbitrary-length integer reads; passing an unvalidated field width from a file format; assuming BigInteger-style semantics.

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


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

Appendix: source

Thrown at app/src/main/java/org/apache/commons/compress/utils/ByteUtils.java:251

    /**
     * {@link ByteConsumer} based on {@link OutputStream}.
     * @since 1.14
     */
    public static class OutputStreamByteConsumer implements ByteConsumer {
        private final OutputStream os;
        public OutputStreamByteConsumer(final OutputStream os) {
            this.os = os;
        }
        @Override
        public void accept(final int b) throws IOException {
            os.write(b);
        }
    }

    private static void checkReadLength(final int length) {
        if (length > 8) {
            throw new IllegalArgumentException("Can't read more than eight bytes into a long value");
        }
    }
}

View on GitHub (pinned to 0152f468fc)