{"record":{"id":"4ffb3325f075305a","repo":"redis/jedis","slug":"buffer-size-0","errorCode":null,"errorMessage":"Buffer size <= 0","messagePattern":"Buffer size <= 0","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/util/RedisInputStream.java","lineNumber":39,"sourceCode":"/**\n * This class assumes (to some degree) that we are reading a RESP stream. As such it assumes certain\n * conventions regarding CRLF line termination. It also assumes that if the Protocol layer requires\n * a byte that if that byte is not there it is a stream error.\n */\npublic class RedisInputStream extends FilterInputStream {\n\n  private static final int INPUT_BUFFER_SIZE = Integer.parseInt(\n      System.getProperty(\"jedis.bufferSize.input\",\n          System.getProperty(\"jedis.bufferSize\", \"8192\")));\n\n  protected final byte[] buf;\n\n  protected int count, limit;\n\n  public RedisInputStream(InputStream in, int size) {\n    super(in);\n    if (size <= 0) {\n      throw new IllegalArgumentException(\"Buffer size <= 0\");\n    }\n    buf = new byte[size];\n  }\n\n  public RedisInputStream(InputStream in) {\n    this(in, INPUT_BUFFER_SIZE);\n  }\n\n  @Experimental\n  public boolean peek(byte b) throws JedisConnectionException {\n    ensureFill(); // in current design, at least one reply is expected. so ensureFillSafe() is not necessary.\n    return buf[count] == b;\n  }\n\n  public byte readByte() throws JedisConnectionException {\n    ensureFill();\n    return buf[count++];\n  }","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/util/RedisInputStream.java#L21-L57","documentation":"RedisInputStream wraps an InputStream with an internal buffer for the RESP protocol parser. The constructor validates that the requested buffer size is positive and throws IllegalArgumentException(\"Buffer size <= 0\") otherwise, because a zero/negative buffer cannot hold any bytes.","triggerScenarios":"Constructing `new RedisInputStream(in, 0)` or with a negative size — e.g. a size computed from a config value, constant folding error, or an int overflow.","commonSituations":"Buffer size read from configuration where the value is 0/unset and cast to int without validation; misconfigured custom protocol clients.","solutions":["Pass a positive size (use the no-arg constructor RedisInputStream(in) to get the default INPUT_BUFFER_SIZE).","Clamp/validate your configured size before construction: Math.max(minBufferSize, configuredSize).","If the size is computed, check the computation for overflow or zero-division results."],"exampleFix":"// before\nint size = config.getBufferSize(); // 0 when unset\nRedisInputStream in = new RedisInputStream(raw, size); // throws\n// after\nint size = Math.max(1024, config.getBufferSize());\nRedisInputStream in = new RedisInputStream(raw, size);","handlingStrategy":"validation","validationCode":"static RedisInputStream safeWrap(InputStream in, int size) {\n  if (size <= 0) size = 8192; // or use RedisInputStream(in) default\n  return new RedisInputStream(in, size);\n}","typeGuard":null,"tryCatchPattern":"try {\n  stream = new RedisInputStream(in, size);\n} catch (IllegalArgumentException e) {\n  stream = new RedisInputStream(in); // default buffer\n}","preventionTips":["Prefer the single-argument constructor to get the default buffer size.","Validate configured buffer sizes at config load time (size > 0).","Watch for computed sizes that can be zero after int arithmetic."],"tags":["buffer","constructor","argument-value","protocol"],"backgroundTag":"invalid-config-value","analyzedSha":"6dac31d4c224fb3257c216f3985340c6f500cdcb","analyzedAt":"2026-09-08T04:55:01.204Z","contentChangedAt":"2026-09-08T04:55:01.204Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}