MuntashirAkon/AppManager · error · IndexOutOfBoundsException

offs(" + offs + ") < 0.

Error message

offs(" + offs + ") < 0.

What it means

BZip2CompressorInputStream.read(byte[], int offs, int len) throws IndexOutOfBoundsException when offs is negative. This mirrors standard InputStream contract argument checking before any decompression work happens.

Source

Thrown at app/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java:137

    public int read() throws IOException {
        if (this.bin != null) {
            final int r = read0();
            count(r < 0 ? -1 : 1);
            return r;
        }
        throw new IOException("Stream closed");
    }

    /*
     * (non-Javadoc)
     *
     * @see java.io.InputStream#read(byte[], int, int)
     */
    @Override
    public int read(final byte[] dest, final int offs, final int len)
            throws IOException {
        if (offs < 0) {
            throw new IndexOutOfBoundsException("offs(" + offs + ") < 0.");
        }
        if (len < 0) {
            throw new IndexOutOfBoundsException("len(" + len + ") < 0.");
        }
        if (offs + len > dest.length) {
            throw new IndexOutOfBoundsException("offs(" + offs + ") + len("
                    + len + ") > dest.length(" + dest.length + ").");
        }
        if (this.bin == null) {
            throw new IOException("Stream closed");
        }
        if (len == 0) {
            return 0;
        }

        final int hi = offs + len;
        int destOffs = offs;
        int b;

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Validate offs >= 0, len >= 0, and offs+len <= dest.length before calling read
  2. Check the offset computation for integer underflow
  3. Verify argument order — offs and len may be swapped at the call site
  4. Catch IndexOutOfBoundsException and clamp/log the offending arguments

Example fix

// before
int n = stream.read(buf, off, len); // off could be negative
// after
if (off < 0 || len < 0 || off + len > buf.length) {
    throw new IllegalArgumentException("bad buffer range: off=" + off + " len=" + len);
}
int n = stream.read(buf, off, len);
Defensive patterns

Strategy: validation

Validate before calling

if (offs < 0 || len < 0 || offs + len > dest.length) {
    throw new IllegalArgumentException("invalid read range: offs=" + offs + " len=" + len + " buf.length=" + dest.length);
}
int n = stream.read(dest, offs, len);

Try / catch

try {
    int n = stream.read(dest, offs, len);
} catch (IndexOutOfBoundsException e) {
    log.error("Bad read range offs={}, len={}, buf={}", offs, len, dest.length, e);
    throw e;
}

Prevention

When it happens

Trigger: Passing a negative offs to the three-argument read(); usually from unvalidated offset variables, integer underflow in offset arithmetic, or wrong-variable arguments (swapped offs/len).

Common situations: Buffer-splitting code computing offsets with subtraction that underflows; passing -1 from a previous failed operation; copy-paste where len was intended.

Related errors


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