{"record":{"id":"982b817aded674be","repo":"apache/hadoop","slug":"invalid-buffer-not-of-length","errorCode":null,"errorMessage":"Invalid buffer, not of length {}","messagePattern":"Invalid buffer, not of length (.+?)","errorType":"exception","errorClass":"HadoopIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/erasurecode/rawcoder/ByteArrayDecodingState.java","lineNumber":104,"sourceCode":"    ByteBufferDecodingState bbdState = new ByteBufferDecodingState(decoder,\n        decodeLength, erasedIndexes, newInputs, newOutputs);\n    return bbdState;\n  }\n\n  /**\n   * Check and ensure the buffers are of the desired length.\n   * @param buffers the buffers to check\n   */\n  void checkInputBuffers(byte[][] buffers) {\n    int validInputs = 0;\n\n    for (byte[] buffer : buffers) {\n      if (buffer == null) {\n        continue;\n      }\n\n      if (buffer.length != decodeLength) {\n        throw new HadoopIllegalArgumentException(\n            \"Invalid buffer, not of length \" + decodeLength);\n      }\n\n      validInputs++;\n    }\n\n    if (validInputs < decoder.getNumDataUnits()) {\n      throw new HadoopIllegalArgumentException(\n          \"No enough valid inputs are provided, not recoverable\");\n    }\n  }\n\n  /**\n   * Check and ensure the buffers are of the desired length.\n   * @param buffers the buffers to check\n   */\n  void checkOutputBuffers(byte[][] buffers) {\n    for (byte[] buffer : buffers) {","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/erasurecode/rawcoder/ByteArrayDecodingState.java#L86-L122","documentation":"When a byte-array raw decode starts, ByteArrayDecodingState sets decodeLength from the first non-null input's array length and then requires every non-null input byte[] to have exactly that length. Any input longer or shorter than the first valid input throws HadoopIllegalArgumentException(\"Invalid buffer, not of length <decodeLength>\"). Inputs represent same-sized stripes of different units, so mixed lengths are a caller bug.","triggerScenarios":"Calling RawErasureDecoder.decode(byte[][], int[], byte[][]) with input arrays of differing lengths — e.g., one unit's read returned a short final chunk while others were padded, or buffers were allocated from different sizes.","commonSituations":"Striped reads where the last block-group chunk is not zero-padded to the cell/stripe length; heterogeneous buffer allocation; manually assembled inputs from cached chunks of different vintages.","solutions":["Pad every input to the same stripe length (zero-pad the short final chunk, as HDFS does for the last stripe)","Allocate all input buffers with identical length before filling them","Pre-check that all non-null inputs share one length before invoking decode"],"exampleFix":"// before\nbyte[][] inputs = { new byte[cellSize], Arrays.copyOf(chunk, chunkLen) };\ndecoder.decode(inputs, erased, outputs); // short second input -> throws\n\n// after\nbyte[][] inputs = new byte[numTotalUnits][cellSize];\nSystem.arraycopy(chunk, 0, inputs[1], 0, chunkLen); // zero-padded remainder","handlingStrategy":"validation","validationCode":"byte[] first = CoderUtil.findFirstValidInput(inputs);\nfor (byte[] b : inputs) {\n  if (b != null && b.length != first.length) {\n    throw new IllegalArgumentException(\"Input length \" + b.length\n        + \" != \" + first.length + \"; pad all inputs to one stripe length\");\n  }\n}\ndecoder.decode(inputs, erased, outputs);","typeGuard":null,"tryCatchPattern":"try {\n  decoder.decode(inputs, erased, outputs);\n} catch (HadoopIllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Invalid buffer, not of length\")) {\n    padAndRetry(); // normalize all inputs to one length, then decode again\n  }\n}","preventionTips":["Always zero-pad the final short chunk of a stripe to the full stripe length","Allocate all input arrays with one common size constant","Assert uniform input lengths in tests for striped-read code"],"tags":["erasure-coding","buffer-validation","hadoop-common"],"backgroundTag":"buffer-length-mismatch","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}