{"record":{"id":"fc9ff727525f289d","repo":"MuntashirAkon/AppManager","slug":"offs-offs-0","errorCode":null,"errorMessage":"offs(\" + offs + \") < 0.","messagePattern":"offs\\(\" \\+ offs \\+ \"\\) < 0\\.","errorType":"validation","errorClass":"IndexOutOfBoundsException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java","lineNumber":137,"sourceCode":"    public int read() throws IOException {\n        if (this.bin != null) {\n            final int r = read0();\n            count(r < 0 ? -1 : 1);\n            return r;\n        }\n        throw new IOException(\"Stream closed\");\n    }\n\n    /*\n     * (non-Javadoc)\n     *\n     * @see java.io.InputStream#read(byte[], int, int)\n     */\n    @Override\n    public int read(final byte[] dest, final int offs, final int len)\n            throws IOException {\n        if (offs < 0) {\n            throw new IndexOutOfBoundsException(\"offs(\" + offs + \") < 0.\");\n        }\n        if (len < 0) {\n            throw new IndexOutOfBoundsException(\"len(\" + len + \") < 0.\");\n        }\n        if (offs + len > dest.length) {\n            throw new IndexOutOfBoundsException(\"offs(\" + offs + \") + len(\"\n                    + len + \") > dest.length(\" + dest.length + \").\");\n        }\n        if (this.bin == null) {\n            throw new IOException(\"Stream closed\");\n        }\n        if (len == 0) {\n            return 0;\n        }\n\n        final int hi = offs + len;\n        int destOffs = offs;\n        int b;","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java#L119-L155","documentation":"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.","triggerScenarios":"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).","commonSituations":"Buffer-splitting code computing offsets with subtraction that underflows; passing -1 from a previous failed operation; copy-paste where len was intended.","solutions":["Validate offs >= 0, len >= 0, and offs+len <= dest.length before calling read","Check the offset computation for integer underflow","Verify argument order — offs and len may be swapped at the call site","Catch IndexOutOfBoundsException and clamp/log the offending arguments"],"exampleFix":"// before\nint n = stream.read(buf, off, len); // off could be negative\n// after\nif (off < 0 || len < 0 || off + len > buf.length) {\n    throw new IllegalArgumentException(\"bad buffer range: off=\" + off + \" len=\" + len);\n}\nint n = stream.read(buf, off, len);","handlingStrategy":"validation","validationCode":"if (offs < 0 || len < 0 || offs + len > dest.length) {\n    throw new IllegalArgumentException(\"invalid read range: offs=\" + offs + \" len=\" + len + \" buf.length=\" + dest.length);\n}\nint n = stream.read(dest, offs, len);","typeGuard":null,"tryCatchPattern":"try {\n    int n = stream.read(dest, offs, len);\n} catch (IndexOutOfBoundsException e) {\n    log.error(\"Bad read range offs={}, len={}, buf={}\", offs, len, dest.length, e);\n    throw e;\n}","preventionTips":["Always bounds-check offs/len before multi-byte reads","Watch for integer underflow when computing offsets","Double-check argument order (dest, offs, len) at call sites"],"tags":["bzip2","index-out-of-bounds","argument-validation","io"],"backgroundTag":"index-out-of-bounds","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}