DrKLO/Telegram · error
Invalid JPEG quality value!\n
Error message
Invalid JPEG quality value!\n
What it means
yuvjpeg parses argv[1] as the JPEG quality via strtol. If errno is non-zero after the conversion (overflow/no-digits) OR the value is < 0 or > 100, it prints `Invalid JPEG quality value!` and returns 1. This guards the libjpeg quality parameter, which only has defined behaviour in [0,100].
Source
Thrown at TMessagesProj/jni/mozjpeg/yuvjpeg.c:129
JSAMPROW cbrow_pointer[8];
JSAMPROW crrow_pointer[8];
JSAMPROW *plane_pointer[3];
int y;
if (argc != 5) {
fprintf(stderr, "Required arguments:\n");
fprintf(stderr, "1. JPEG quality value, 0-100\n");
fprintf(stderr, "2. Image size (e.g. '512x512')\n");
fprintf(stderr, "3. Path to YUV input file\n");
fprintf(stderr, "4. Path to JPG output file\n");
return 1;
}
errno = 0;
quality = strtol(argv[1], NULL, 10);
if (errno != 0 || quality < 0 || quality > 100) {
fprintf(stderr, "Invalid JPEG quality value!\n");
return 1;
}
matches = sscanf(argv[2], "%dx%d", &luma_width, &luma_height);
if (matches != 2) {
fprintf(stderr, "Invalid image size input!\n");
return 1;
}
if (luma_width <= 0 || luma_height <= 0) {
fprintf(stderr, "Invalid image size input!\n");
return 1;
}
chroma_width = (luma_width + 1) >> 1;
chroma_height = (luma_height + 1) >> 1;
/* Will check these for validity when opening via 'fopen'. */
yuv_path = argv[3];View on GitHub (pinned to 45ab8f4308)
Solutions
- Pass an integer quality strictly in [0,100].
- Clamp the value in the caller: q = max(0, min(100, q)).
- Validate argv[1] matches ^[0-9]{1,3}$ and is <= 100 before invoking.
Example fix
// before yuvjpeg 120 512x512 in.yuv out.jpg // after yuvjpeg 100 512x512 in.yuv out.jpg
Defensive patterns
Strategy: validation
Validate before calling
#include <errno.h>
#include <stdlib.h>
errno = 0;
long q = strtol(argv[1], NULL, 10);
if (errno != 0 || q < 0 || q > 100) { /* reject; do not invoke yuvjpeg */ } Prevention
- Clamp quality to [0,100] in the caller.
- Reject non-integer quality strings upstream.
- Watch for trailing units like '%' or 'q' attached to the number.
When it happens
Trigger: Invoking `yuvjpeg <q> ...` where <q> is non-numeric, empty, out of integer range (ERANGE), or numerically outside 0-100 (e.g. 120 or -5).
Common situations: Passing a float like 90.5 (strtol stops at '.', may parse 90 but is suspect), a percentage sign like '90%', a blank argument, or a value over 100 from a misconfigured UI slider.
Related errors
- Required arguments:\n
- Invalid image size input!\n
- Invalid path to YUV file!\n
- Unexpected input format!\n
- %s: can't open %s
AI-assisted analysis of DrKLO/Telegram@45ab8f4308 (2026-08-14).
Data as JSON: /api/errors/e37ee52575c36c34.
Report an issue: GitHub.