{"record":{"id":"2b7a4fd592b6d133","repo":"apache/hadoop","slug":"length-not-matched-length-length-checksum-get","errorCode":null,"errorMessage":"Length not matched: length=${length}, checksum.getLength()=${checksum.getLength()}","messagePattern":"Length not matched: length=(.+?), checksum\\.getLength\\(\\)=(.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/JsonUtilClient.java","lineNumber":573,"sourceCode":"    case CRC32:\n      checksum = new MD5MD5CRC32GzipFileChecksum();\n      break;\n    case CRC32C:\n      checksum = new MD5MD5CRC32CastagnoliFileChecksum();\n      break;\n    default:\n      throw new IOException(\"Unknown algorithm: \" + algorithm);\n    }\n    checksum.readFields(in);\n\n    //check algorithm name\n    if (!checksum.getAlgorithmName().equals(algorithm)) {\n      throw new IOException(\"Algorithm not matched. Expected \" + algorithm\n          + \", Received \" + checksum.getAlgorithmName());\n    }\n    //check length\n    if (length != checksum.getLength()) {\n      throw new IOException(\"Length not matched: length=\" + length\n          + \", checksum.getLength()=\" + checksum.getLength());\n    }\n\n    return checksum;\n  }\n\n  /** Convert a Json map to a AclStatus object. */\n  static AclStatus toAclStatus(final Map<?, ?> json) {\n    if (json == null) {\n      return null;\n    }\n\n    final Map<?, ?> m = (Map<?, ?>) json.get(AclStatus.class.getSimpleName());\n\n    AclStatus.Builder aclStatusBuilder = new AclStatus.Builder();\n    aclStatusBuilder.owner((String) m.get(\"owner\"));\n    aclStatusBuilder.group((String) m.get(\"group\"));\n    aclStatusBuilder.stickyBit((Boolean) m.get(\"stickyBit\"));","sourceCodeStart":555,"sourceCodeEnd":591,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/JsonUtilClient.java#L555-L591","documentation":"MD5MD5CRC32FileChecksum has a fixed serialized length, and JsonUtilClient compares that length with the length field from the WebHDFS GETFILECHECKSUM response. This IOException means the advertised length differs from the length of the checksum object decoded from the bytes field, so the response is internally inconsistent.","triggerScenarios":"getFileChecksum through WebHDFS returns a length field that is not the expected MD5MD5CRC32 checksum length while the response is otherwise decoded. A truncated or hand-crafted bytes field, a proxy-modified length, or an incompatible response schema can produce it.","commonSituations":"A WebHDFS gateway constructs or patches checksum JSON incorrectly; a mock returns arbitrary lengths; an HTTP cache serves a partial or mixed response; client and server versions disagree on checksum serialization.","solutions":["Inspect the raw GETFILECHECKSUM JSON and confirm its length matches the fixed MD5MD5CRC32 checksum size emitted by the same Hadoop version.","Remove or fix intermediaries that rewrite or partially cache the checksum response.","Use a matching Hadoop client against the real NameNode endpoint.","Fall back to computing a checksum by reading the file if the server checksum format cannot be trusted."],"exampleFix":"// before\nMap<?, ?> json = WebHdfsFileSystem.jsonParse(connection, false);\n\n// after: validate the response before decoding\nObject cs = json.get(\"FileChecksum\");\nif (cs == null || ((Map<?, ?>) cs).get(\"length\") == null\n    || ((Map<?, ?>) cs).get(\"bytes\") == null) {\n  throw new IOException(\"Incomplete WebHDFS checksum response: \" + json);\n}\nreturn JsonUtilClient.toMD5MD5CRC32FileChecksum(json);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  return fs.getFileChecksum(path);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Length not matched\")) {\n    throw new IOException(\"Invalid WebHDFS checksum length for \" + path, e);\n  }\n  throw e;\n}","preventionTips":["Keep checksum JSON fields length and bytes together when caching or forwarding responses.","Use matching Hadoop versions for checksum verification across a cluster.","Prefer reading the file and hashing it when an intermediary cannot preserve WebHDFS response integrity."],"tags":["java","hadoop","webhdfs","checksum","response-validation"],"backgroundTag":"checksum-mismatch","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}