{"record":{"id":"8ea8937e3ae24a54","repo":"MuntashirAkon/AppManager","slug":"offs-offs-len-len-dest-length-dest-length","errorCode":null,"errorMessage":"offs(\" + offs + \") + len(\" + len + \") > dest.length(\" + dest.length + \").","messagePattern":"offs\\(\" \\+ offs \\+ \"\\) \\+ len\\(\" \\+ len \\+ \"\\) > dest\\.length\\(\" \\+ dest\\.length \\+ \"\\)\\.","errorType":"validation","errorClass":"IndexOutOfBoundsException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java","lineNumber":143,"sourceCode":"        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;\n        while (destOffs < hi && ((b = read0()) >= 0)) {\n            dest[destOffs++] = (byte) b;\n            count(1);\n        }\n\n        return (destOffs == offs) ? -1 : (destOffs - offs);","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java#L125-L161","documentation":"read(byte[], int, int) throws IndexOutOfBoundsException when offs + len exceeds dest.length, i.e. the caller asked to fill more bytes than the buffer can hold at the given offset. This is a fail-fast bounds check identical to the one in InputStream's contract.","triggerScenarios":"Calling read(dest, offs, len) where offs + len > dest.length, e.g. read(buf, 5, buf.length) or read(buf, 10, buf.length - 5).","commonSituations":"Reusing buffer code written for a different buffer size; passing offs without shrinking len accordingly; copying logic between byte[] buffers of different capacities.","solutions":["Compute len as dest.length - offs, or clamp: len = Math.min(len, dest.length - offs).","Verify the buffer is large enough for the requested read before the call.","Prefer the simpler read(byte[]) or a fixed-size chunk loop with len = buf.length and offs = 0."],"exampleFix":"// before\nint n = stream.read(buf, 10, buf.length);\n// after\nint n = stream.read(buf, 10, buf.length - 10);","handlingStrategy":"validation","validationCode":"if (offs < 0 || len < 0 || offs + len > dest.length) {\n    throw new IllegalArgumentException(\"bad buffer bounds: offs=\" + offs + \" len=\" + len);\n}","typeGuard":"static boolean fitsInBuffer(int offs, int len, byte[] dest) {\n    return dest != null && offs >= 0 && len >= 0 && offs <= dest.length - len;\n}","tryCatchPattern":"try {\n    int n = in.read(dest, offs, len);\n} catch (IndexOutOfBoundsException e) {\n    // fix caller-side bounds; do not retry same args\n}","preventionTips":["Derive len from the buffer: len = dest.length - offs.","Keep offs at 0 and use full-size buffers where possible.","Unit-test read wrappers with boundary offsets."],"tags":["io","argument-validation","indexoutofboundsexception"],"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"}