{"record":{"id":"828bd41061c941ec","repo":"DrKLO/Telegram","slug":"comment-text-may-not-exceed-u-bytes-n","errorCode":null,"errorMessage":"Comment text may not exceed %u bytes\\n","messagePattern":"Comment text may not exceed %u bytes\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"TMessagesProj/jni/mozjpeg/wrjpgcom.c","lineNumber":556,"sourceCode":"  }\n#else\n  outfile = stdout;\n#endif\n#endif /* TWO_FILE_COMMANDLINE */\n\n  /* Collect comment text from comment_file or stdin, if necessary */\n  if (comment_arg == NULL) {\n    FILE *src_file;\n    int c;\n\n    comment_arg = (char *)malloc((size_t)MAX_COM_LENGTH);\n    if (comment_arg == NULL)\n      ERREXIT(\"Insufficient memory\");\n    comment_length = 0;\n    src_file = (comment_file != NULL ? comment_file : stdin);\n    while ((c = getc(src_file)) != EOF) {\n      if (comment_length >= (unsigned int)MAX_COM_LENGTH) {\n        fprintf(stderr, \"Comment text may not exceed %u bytes\\n\",\n                (unsigned int)MAX_COM_LENGTH);\n        exit(EXIT_FAILURE);\n      }\n      comment_arg[comment_length++] = (char)c;\n    }\n    if (comment_file != NULL)\n      fclose(comment_file);\n  }\n\n  /* Copy JPEG headers until SOFn marker;\n   * we will insert the new comment marker just before SOFn.\n   * This (a) causes the new comment to appear after, rather than before,\n   * existing comments; and (b) ensures that comments come after any JFIF\n   * or JFXX markers, as required by the JFIF specification.\n   */\n  marker = scan_JPEG_header(keep_COM);\n  /* Insert the new COM marker, but only if nonempty text has been supplied */\n  if (comment_length > 0) {","sourceCodeStart":538,"sourceCodeEnd":574,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/mozjpeg/wrjpgcom.c#L538-L574","documentation":"If no -comment and no -cfile was supplied, wrjpgcom reads the comment text from comment_file (or stdin) byte-by-byte into a MAX_COM_LENGTH (65000) buffer. If the loop reaches comment_length >= 65000 before EOF, it prints this message and exits EXIT_FAILURE. This bounds the JPEG COM marker payload to the JPEG spec ceiling.","triggerScenarios":"Running `wrjpgcom [input]` (reading comment from stdin/comment_file) and feeding more than 65000 bytes of comment text.","commonSituations":"Redirecting a large text file or pipe into wrjpgcom's comment input without a size check, or an interactive session pasting a very long comment.","solutions":["Limit comment source to under 65000 bytes before feeding it in.","Pre-truncate the input: `head -c 64999 comment.txt | wrjpgcom ...`.","If a larger comment is truly needed, note JPEG COM markers cannot exceed ~65533 bytes; split across multiple COM markers via custom tooling instead."],"exampleFix":"// before\nwrjpgcom -cfile big.txt photo.jpg   # big.txt > 65000 bytes\n// after\nhead -c 65000 big.txt > /tmp/c.txt && wrjpgcom -cfile /tmp/c.txt photo.jpg","handlingStrategy":"validation","validationCode":"#define MAX_COM_LENGTH 65000L\n/* bound the comment source fed via stdin/comment_file */\nif (source_byte_count >= (size_t)MAX_COM_LENGTH) {\n    /* truncate or reject before feeding wrjpgcom */\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pre-truncate comment input to < 65000 bytes (e.g. head -c 64999).","Check the source file size before redirecting it as comment input.","Remember JPEG COM markers are hard-capped near 64KB."],"tags":["cli","jpeg","mozjpeg","wrjpgcom","input-validation","limits","stdin"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}