{"record":{"id":"7fb99b6e3a96e4da","repo":"apache/hadoop","slug":"illegal-buffer-length-len","errorCode":null,"errorMessage":"Illegal buffer length \" + len","messagePattern":"Illegal buffer length \" \\+ len","errorType":"validation","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawPathHandle.java","lineNumber":108,"sourceCode":"\n  private void writeObject(ObjectOutputStream out) throws IOException {\n    out.defaultWriteObject();\n    out.writeInt(fd.remaining());\n    if (fd.hasArray()) {\n      out.write(fd.array(), fd.position(), fd.remaining());\n    } else {\n      byte[] x = new byte[fd.remaining()];\n      fd.slice().get(x);\n      out.write(x);\n    }\n  }\n\n  private void readObject(ObjectInputStream in)\n      throws IOException, ClassNotFoundException {\n    in.defaultReadObject();\n    int len = in.readInt();\n    if (len < 0 || len > MAX_SIZE) {\n      throw new IOException(\"Illegal buffer length \" + len);\n    }\n    byte[] x = new byte[len];\n    in.readFully(x);\n    fd = ByteBuffer.wrap(x);\n  }\n\n  private void readObjectNoData() throws ObjectStreamException {\n    throw new InvalidObjectException(\"Stream data required\");\n  }\n\n}\n","sourceCodeStart":90,"sourceCodeEnd":120,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawPathHandle.java#L90-L120","documentation":"Thrown while Java-deserializing a RawPathHandle: after defaultReadObject, the stream's next int is the handle byte length, and it must be in [0, 1<<20] (1 MiB, RawPathHandle.MAX_SIZE). A length outside that window means the stream is corrupted, truncated, version-skewed between writer and reader, or deliberately hostile (the cap is an OOM guard against crafted length fields). Deserialization is aborted with IOException.","triggerScenarios":"ObjectInputStream.readObject() on bytes that were not produced by RawPathHandle.writeObject (truncation mid-stream, garbage payload, an int misaligned by a class-shape change), or an attacker-controlled stream declaring length > 1048576 or negative.","commonSituations":"Passing serialized PathHandles between client and server versions whose serialization layout differs; storing handle blobs in a queue/db where the payload got mangled; accepting serialized objects over an unauthenticated endpoint.","solutions":["Discard the stored/queued handle and re-create it from the source FileSystem rather than repairing the bytes","Verify end-to-end integrity: checksum the serialized blob, or confirm both ends run the same Hadoop version","Never ObjectInputStream.readObject() on untrusted data; wrap handles in a length- and checksum-validated envelope"],"exampleFix":"// before: trusting a raw byte stream\ntry (ObjectInputStream in = new ObjectInputStream(bais)) {\n  RawPathHandle h = (RawPathHandle) in.readObject();\n}\n\n// after: rebuild from the authoritative source\nPathHandle h = fs.getPathHandle(fs.getFileStatus(p));","handlingStrategy":"try-catch","validationCode":"// producer side: refuse to emit oversized handles\nByteBuffer b = handle.bytes();\nif (b.remaining() > RawPathHandle.MAX_SIZE) {\n  throw new IOException(\"Handle exceeds \" + RawPathHandle.MAX_SIZE + \" bytes\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  Object o = in.readObject();\n} catch (IOException e) {\n  // \"Illegal buffer length N\" -> corrupt/version-skewed stream\n  PathHandle h = fs.getPathHandle(fs.getFileStatus(p)); // rebuild from source\n}","preventionTips":["Version both ends of any channel that carries serialized PathHandles","Checksum serialized blobs at rest so corruption is detected before readObject","Never deserialize objects from unauthenticated sources"],"tags":["hadoop","pathhandle","deserialization","corruption"],"backgroundTag":"deserialization-payload-validation","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}