{"record":{"id":"f6fa0faffa4ca9b4","repo":"MuntashirAkon/AppManager","slug":"offs-offs-len-len-buf-length-buf-length","errorCode":null,"errorMessage":"offs(\" + offs + \") + len(\" + len + \") > buf.length(\" + buf.length + \").","messagePattern":"offs\\(\" \\+ offs \\+ \"\\) \\+ len\\(\" \\+ len \\+ \"\\) > buf\\.length\\(\" \\+ buf\\.length \\+ \"\\)\\.","errorType":"validation","errorClass":"IndexOutOfBoundsException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java","lineNumber":613,"sourceCode":"    /**\n     * Returns the blocksize parameter specified at construction time.\n     * @return the blocksize parameter specified at construction time\n     */\n    public final int getBlockSize() {\n        return this.blockSize100k;\n    }\n\n    @Override\n    public void write(final byte[] buf, 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 > buf.length) {\n            throw new IndexOutOfBoundsException(\"offs(\" + offs + \") + len(\"\n                    + len + \") > buf.length(\"\n                    + buf.length + \").\");\n        }\n        if (closed) {\n            throw new IOException(\"Stream closed\");\n        }\n\n        for (final int hi = offs + len; offs < hi;) {\n            write0(buf[offs++]);\n        }\n    }\n\n    /**\n     * Keeps track of the last bytes written and implicitly performs\n     * run-length encoding as the first step of the bzip2 algorithm.\n     */\n    private void write0(int b) throws IOException {\n        if (this.currentChar != -1) {","sourceCodeStart":595,"sourceCodeEnd":631,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java#L595-L631","documentation":"write(byte[], int, int) checks offs + len against buf.length and throws IndexOutOfBoundsException if the requested range extends past the end of the array. The library refuses to read beyond the supplied buffer, per the OutputStream contract.","triggerScenarios":"Calling write(buf, offs, len) with offs + len > buf.length — e.g. offs near the buffer end, or len counted from a different (larger) buffer.","commonSituations":"Mixing up buffer/offset pairs after reusing a smaller scratch buffer; forgetting to shrink len after a partial read; integer overflow of offs+len with huge offsets.","solutions":["Recompute len as Math.min(len, buf.length - offs) before writing.","Verify offs/len refer to the same buffer actually passed in.","Add a debug assertion upstream that offs + len <= buf.length to catch the mismatch at its source."],"exampleFix":"// before\nout.write(buf, off, chunk);\n// after\nout.write(buf, off, Math.min(chunk, buf.length - off));","handlingStrategy":"validation","validationCode":"if (offs < 0 || len < 0 || offs > buf.length - len) {\n    throw new IllegalArgumentException(\"write range exceeds buffer: offs=\" + offs + \" len=\" + len + \" cap=\" + buf.length);\n}\nout.write(buf, offs, len);","typeGuard":null,"tryCatchPattern":"try {\n    out.write(buf, offs, len);\n} catch (IndexOutOfBoundsException e) {\n    // clamp: out.write(buf, offs, Math.min(len, buf.length - offs));\n}","preventionTips":["Always pair a buffer with its own offset/length metadata, never mix buffers.","Use Math.min(len, buf.length - offs) when copying partial chunks.","Unit-test copy loops with buffers sized at exact chunk boundaries."],"tags":["io","argument-validation","bzip2","array-bounds"],"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"}