{"record":{"id":"c835d74142cb6333","repo":"DrKLO/Telegram","slug":"warning-md5-hash-size-is-wrong","errorCode":null,"errorMessage":"WARNING: MD5 hash size is wrong.\n","messagePattern":"WARNING: MD5 hash size is wrong\\.\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"TMessagesProj/jni/mozjpeg/md5/md5cmp.c","lineNumber":44,"sourceCode":" * POSSIBILITY OF SUCH DAMAGE.\n */\n\n#include <stdio.h>\n#include <string.h>\n#include \"./md5.h\"\n#include \"../tjutil.h\"\n\nint main(int argc, char *argv[])\n{\n  char *md5sum = NULL, buf[65];\n\n  if (argc < 3) {\n    fprintf(stderr, \"USAGE: %s <correct MD5 sum> <file>\\n\", argv[0]);\n    return -1;\n  }\n\n  if (strlen(argv[1]) != 32)\n    fprintf(stderr, \"WARNING: MD5 hash size is wrong.\\n\");\n\n  md5sum = MD5File(argv[2], buf);\n  if (!md5sum) {\n    perror(\"Could not obtain MD5 sum\");\n    return -1;\n  }\n\n  if (!strcasecmp(md5sum, argv[1])) {\n    fprintf(stderr, \"%s: OK\\n\", argv[2]);\n    return 0;\n  } else {\n    fprintf(stderr, \"%s: FAILED.  Checksum is %s\\n\", argv[2], md5sum);\n    return -1;\n  }\n}\n","sourceCodeStart":26,"sourceCodeEnd":60,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/mozjpeg/md5/md5cmp.c#L26-L60","documentation":"This is a warning (not a fatal error) printed when the first argument to md5cmp is not exactly 32 characters long. A valid MD5 digest is always 32 hexadecimal characters. The program continues execution after the warning and attempts the comparison anyway, so a mismatch may follow. The strlen check is a sanity guard to alert the user that the provided hash is malformed.","triggerScenarios":"Passing a hash string that is truncated, has extra whitespace or a newline appended, is base64-encoded instead of hex, or was copied with a prefix like 'md5:' included. The strlen(argv[1]) != 32 check fires on any deviation from exactly 32 characters.","commonSituations":"Piping the output of md5sum (which includes a filename suffix) without trimming; shell variable containing a trailing newline from command substitution; hash stored in a config file with surrounding quotes or whitespace; base64-encoded digest mistakenly used instead of hex.","solutions":["Ensure the hash argument is exactly 32 hex characters: trim whitespace, newlines, and any 'MD5' prefix.","If the hash comes from md5sum output, extract only the first field: hash=$(md5sum file | cut -d' ' -f1).","Validate the hash length before passing it: reject anything that is not 32 characters of [0-9a-fA-F]."],"exampleFix":"# before\nmd5sum=$(md5sum input.jpg)\nmd5cmp \"$md5sum\" input.jpg\n# after\nmd5sum=$(md5sum input.jpg | cut -d' ' -f1)\nmd5cmp \"$md5sum\" input.jpg","handlingStrategy":"validation","validationCode":"# Validate hash format before passing to md5cmp\nhash=\"$1\"\nif [ ${#hash} -ne 32 ] || ! echo \"$hash\" | grep -qE '^[0-9a-fA-F]{32}$'; then\n  echo \"Error: hash must be 32 hex characters\" >&2\n  exit 1\nfi\nmd5cmp \"$hash\" \"$2\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Strip whitespace and newlines from hash strings before passing them.","Validate that the hash matches ^[0-9a-fA-F]{32}$ before invoking md5cmp.","When using command substitution, pipe through tr -d to remove trailing newlines."],"tags":["cli","validation","md5","mozjpeg"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}