DrKLO/Telegram · error
Comment text may not exceed %u bytes\n
Error message
Comment text may not exceed %u bytes\n
What it means
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.
Source
Thrown at TMessagesProj/jni/mozjpeg/wrjpgcom.c:556
}
#else
outfile = stdout;
#endif
#endif /* TWO_FILE_COMMANDLINE */
/* Collect comment text from comment_file or stdin, if necessary */
if (comment_arg == NULL) {
FILE *src_file;
int c;
comment_arg = (char *)malloc((size_t)MAX_COM_LENGTH);
if (comment_arg == NULL)
ERREXIT("Insufficient memory");
comment_length = 0;
src_file = (comment_file != NULL ? comment_file : stdin);
while ((c = getc(src_file)) != EOF) {
if (comment_length >= (unsigned int)MAX_COM_LENGTH) {
fprintf(stderr, "Comment text may not exceed %u bytes\n",
(unsigned int)MAX_COM_LENGTH);
exit(EXIT_FAILURE);
}
comment_arg[comment_length++] = (char)c;
}
if (comment_file != NULL)
fclose(comment_file);
}
/* Copy JPEG headers until SOFn marker;
* we will insert the new comment marker just before SOFn.
* This (a) causes the new comment to appear after, rather than before,
* existing comments; and (b) ensures that comments come after any JFIF
* or JFXX markers, as required by the JFIF specification.
*/
marker = scan_JPEG_header(keep_COM);
/* Insert the new COM marker, but only if nonempty text has been supplied */
if (comment_length > 0) {View on GitHub (pinned to 45ab8f4308)
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.
Example fix
// before wrjpgcom -cfile big.txt photo.jpg # big.txt > 65000 bytes // after head -c 65000 big.txt > /tmp/c.txt && wrjpgcom -cfile /tmp/c.txt photo.jpg
Defensive patterns
Strategy: validation
Validate before calling
#define MAX_COM_LENGTH 65000L
/* bound the comment source fed via stdin/comment_file */
if (source_byte_count >= (size_t)MAX_COM_LENGTH) {
/* truncate or reject before feeding wrjpgcom */
} Prevention
- 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.
When it happens
Trigger: Running `wrjpgcom [input]` (reading comment from stdin/comment_file) and feeding more than 65000 bytes of comment text.
Common situations: 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.
Related errors
- Comment text may not exceed %u bytes
- %s: can't open %s
- %s: can't open %s\n
- %s: can't open stdin\n
- %s: must name one input and one output file\n
AI-assisted analysis of DrKLO/Telegram@45ab8f4308 (2026-08-14).
Data as JSON: /api/errors/828bd41061c941ec.
Report an issue: GitHub.