{"record":{"id":"6be5f6232a02e7f7","repo":"DrKLO/Telegram","slug":"comment-text-may-not-exceed-u-bytes","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":451,"sourceCode":"      keep_COM = 0;\n    } else if (keymatch(arg, \"cfile\", 2)) {\n      if (++argn >= argc) usage();\n      if ((comment_file = fopen(argv[argn], \"r\")) == NULL) {\n        fprintf(stderr, \"%s: can't open %s\\n\", progname, argv[argn]);\n        exit(EXIT_FAILURE);\n      }\n    } else if (keymatch(arg, \"comment\", 1)) {\n      if (++argn >= argc) usage();\n      comment_arg = argv[argn];\n      /* If the comment text starts with '\"', then we are probably running\n       * under MS-DOG and must parse out the quoted string ourselves.  Sigh.\n       */\n      if (comment_arg[0] == '\"') {\n        comment_arg = (char *)malloc((size_t)MAX_COM_LENGTH);\n        if (comment_arg == NULL)\n          ERREXIT(\"Insufficient memory\");\n        if (strlen(argv[argn]) + 2 >= (size_t)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        strcpy(comment_arg, argv[argn] + 1);\n        for (;;) {\n          comment_length = (unsigned int)strlen(comment_arg);\n          if (comment_length > 0 && comment_arg[comment_length - 1] == '\"') {\n            comment_arg[comment_length - 1] = '\\0'; /* zap terminating quote */\n            break;\n          }\n          if (++argn >= argc)\n            ERREXIT(\"Missing ending quote mark\");\n          if (strlen(comment_arg) + strlen(argv[argn]) + 2 >=\n              (size_t)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          }","sourceCodeStart":433,"sourceCodeEnd":469,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/mozjpeg/wrjpgcom.c#L433-L469","documentation":"When -comment is given a value whose first character is a double-quote, wrjpgcom assumes an MS-DOS-style quoted string and allocates a MAX_COM_LENGTH (65000) byte buffer to reassemble it. This error fires when even the very first token is too long: strlen(argv[argn]) + 2 >= MAX_COM_LENGTH. The +2 accounts for the appended space and terminator used while concatenating further tokens. The process exits EXIT_FAILURE.","triggerScenarios":"Running `wrjpgcom -comment \"<very long string>\"` where the single quoted token (minus trailing quote considerations) already reaches/exceeds 64998 bytes, so no further tokens could ever fit.","commonSituations":"Piping a huge blob into a shell-quoted -comment argument, accidentally passing a file's full contents as an argument, or a script concatenating unbounded user input into the comment.","solutions":["Keep comment text under 65000 bytes; for larger payloads use -cfile with a file instead.","If the text legitimately exceeds the limit, store it in a file and pass -cfile <file>.","Trim or chunk the comment source before constructing the argv."],"exampleFix":"// before\nwrjpgcom -comment \"$(cat huge.txt)\" photo.jpg\n// after\nwrjpgcom -cfile huge.txt photo.jpg","handlingStrategy":"validation","validationCode":"#define MAX_COM_LENGTH 65000L\n/* before building argv, check the quoted comment's first token length */\nif (comment[0] == '\"' && strlen(comment) + 2 >= (size_t)MAX_COM_LENGTH) {\n    /* route long comments through -cfile instead */\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat any comment >= ~64KB as a file payload, not an argv string.","Bound user-supplied comment length at the input boundary.","Prefer -cfile for programmatically generated comments."],"tags":["cli","jpeg","mozjpeg","wrjpgcom","input-validation","limits"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}