{"record":{"id":"7a9d37f53ae728ea","repo":"MuntashirAkon/AppManager","slug":"buffersize-must-be-bigger-than-0","errorCode":null,"errorMessage":"buffersize must be bigger than 0","messagePattern":"buffersize must be bigger than 0","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/org/apache/commons/compress/utils/IOUtils.java","lineNumber":66,"sourceCode":"\n    /**\n     * Copies the content of a InputStream into an OutputStream\n     *\n     * @param input\n     *            the InputStream to copy\n     * @param output\n     *            the target Stream\n     * @param buffersize\n     *            the buffer size to use, must be bigger than 0\n     * @return the number of bytes copied\n     * @throws IOException\n     *             if an error occurs\n     * @throws IllegalArgumentException\n     *             if buffersize is smaller than or equal to 0\n     */\n    public static long copy(final InputStream input, final OutputStream output, final int buffersize) throws IOException {\n        if (buffersize < 1) {\n            throw new IllegalArgumentException(\"buffersize must be bigger than 0\");\n        }\n        final byte[] buffer = new byte[buffersize];\n        int n = 0;\n        long count=0;\n        while (-1 != (n = input.read(buffer))) {\n            output.write(buffer, 0, n);\n            count += n;\n        }\n        return count;\n    }\n\n    /**\n     * Skips the given number of bytes by repeatedly invoking skip on\n     * the given input stream if necessary.\n     *\n     * <p>In a case where the stream's skip() method returns 0 before\n     * the requested number of bytes has been skip this implementation\n     * will fall back to using the read() method.</p>","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/org/apache/commons/compress/utils/IOUtils.java#L48-L84","documentation":"IOUtils.copy(InputStream,OutputStream,int) allocates a byte[buffersize] transfer buffer and rejects buffersize < 1 with IllegalArgumentException, since a zero/negative buffer can never be allocated or used for reads.","triggerScenarios":"Calling IOUtils.copy(input, output, 0) or with a negative buffersize, e.g. passing a user-configured chunk size that defaulted to 0 or a subtraction that yielded <= 0.","commonSituations":"Config file with buffersize=0; integer arithmetic overflow/underflow computing the size; copying the two-arg copy() signature but adding 0 as buffer size.","solutions":["Pass a positive buffersize, e.g. 8192 (8 KB, a common default)","Validate/clamp the configured buffer size before calling","Use the two-argument IOUtils.copy(input, output) overload which picks a sane default"],"exampleFix":"// before\nIOUtils.copy(in, out, bufferSize); // bufferSize == 0\n// after\nIOUtils.copy(in, out, Math.max(1, bufferSize));","handlingStrategy":"validation","validationCode":"if (buffersize < 1) throw new IllegalArgumentException(\"buffersize must be >= 1\");","typeGuard":null,"tryCatchPattern":"try { IOUtils.copy(in, out, size); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"buffersize\")) { IOUtils.copy(in, out, 8192); } else throw e; }","preventionTips":["Use the two-arg copy() overload when no custom size is needed","Sanitize configured buffer sizes with Math.max(1, size)","Guard against arithmetic that can underflow the size computation"],"tags":["io","argument-validation","copy"],"backgroundTag":"invalid-argument-value","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}