{"record":{"id":"2b2e639ae457ef95","repo":"apache/hadoop","slug":"limit-exceeds-buffer-size","errorCode":null,"errorMessage":"Limit exceeds buffer size","messagePattern":"Limit exceeds buffer size","errorType":"exception","errorClass":"IndexOutOfBoundsException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/BoundedByteArrayOutputStream.java","lineNumber":105,"sourceCode":"    } else if (len == 0) {\n      return;\n    }\n\n    if (currentPointer + len > limit) {\n      throw new EOFException(\"Reach the limit of the buffer\");\n    }\n\n    System.arraycopy(b, off, buffer, currentPointer, len);\n    currentPointer += len;\n  }\n\n  /**\n   * Reset the limit \n   * @param newlim New Limit\n   */\n  public void reset(int newlim) {\n    if (newlim > (buffer.length - startOffset)) {\n      throw new IndexOutOfBoundsException(\"Limit exceeds buffer size\");\n    }\n    this.limit = newlim;\n    this.currentPointer = startOffset;\n  }\n\n  /** Reset the buffer */\n  public void reset() {\n    this.limit = buffer.length - startOffset;\n    this.currentPointer = startOffset;\n  }\n\n  /**\n   * Return the current limit.\n   * @return limit.\n   */\n  public int getLimit() {\n    return limit;\n  }","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/BoundedByteArrayOutputStream.java#L87-L123","documentation":"reset(int newlim) re-arms the bounded stream to accept newlim more bytes starting from startOffset. It throws IndexOutOfBoundsException when newlim exceeds the usable capacity (buffer.length - startOffset), because the underlying array cannot physically hold that many bytes.","triggerScenarios":"bbos.reset(buffer.length + extra) or reset(softLimit) after the buffer was constructed with an offset leaving less usable room; passing a size in different units (KB vs bytes) than the buffer was allocated with.","commonSituations":"Retrying a too-large record with 'reset to needed size' logic that forgets the start offset; configuration units mismatch (softLimit configured in KB, buffer allocated in bytes).","solutions":["Clamp the new limit to buffer.length - startOffset before calling reset.","Keep limit and capacity in one place (single constant/config) so they cannot diverge.","If you truly need more room, allocate a larger byte[] and construct a new stream (or use resetBuffer on a subclass) instead of resetting beyond capacity."],"exampleFix":"// before\nbbos.reset(neededSize); // throws if neededSize > buffer.length - startOffset\n\n// after\nbbos.reset(Math.min(neededSize, buffer.length - startOffset));","handlingStrategy":"validation","validationCode":"int usable = buffer.length - startOffset;\nif (newlim > usable) newlim = usable;\nbbos.reset(newlim);","typeGuard":null,"tryCatchPattern":"try {\n  bbos.reset(newlim);\n} catch (IndexOutOfBoundsException e) {\n  throw new IllegalStateException(\"Requested limit \" + newlim + \" exceeds usable capacity \" + (buffer.length - startOffset), e);\n}","preventionTips":["Always clamp reset() limits against buffer.length - startOffset.","Keep buffer sizes and limits in the same units from one config source."],"tags":["hadoop","io","buffer","validation","capacity"],"backgroundTag":"buffer-limit-exceeded","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}