DrKLO/Telegram · error
%s: bogus -crop argument '%s'
Error message
%s: bogus -crop argument '%s'
What it means
jpegtran's -crop argument failed to parse via jtransform_parse_crop_spec(). The expected format is WxH+X+Y (or WxH+X+Y with optional alignment/offset syntax); an unparseable string triggers this fatal error.
Source
Thrown at TMessagesProj/jni/mozjpeg/jpegtran.c:212
/* Select which extra markers to copy. */
if (++argn >= argc) /* advance to next argument */
usage();
if (keymatch(argv[argn], "none", 1)) {
copyoption = JCOPYOPT_NONE;
} else if (keymatch(argv[argn], "comments", 1)) {
copyoption = JCOPYOPT_COMMENTS;
} else if (keymatch(argv[argn], "all", 1)) {
copyoption = JCOPYOPT_ALL;
} else
usage();
} else if (keymatch(arg, "crop", 2)) {
/* Perform lossless cropping. */
#if TRANSFORMS_SUPPORTED
if (++argn >= argc) /* advance to next argument */
usage();
if (!jtransform_parse_crop_spec(&transformoption, argv[argn])) {
fprintf(stderr, "%s: bogus -crop argument '%s'\n",
progname, argv[argn]);
exit(EXIT_FAILURE);
}
prefer_smallest = FALSE;
#else
select_transform(JXFORM_NONE); /* force an error */
#endif
} else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
/* Enable debug printouts. */
/* On first -d, print version identification */
static boolean printed_version = FALSE;
if (!printed_version) {
fprintf(stderr, "%s version %s (build %s)\n",
PACKAGE_NAME, VERSION, BUILD);
fprintf(stderr, "%s\n\n", JCOPYRIGHT);
fprintf(stderr, "Emulating The Independent JPEG Group's software, version %s\n\n",View on GitHub (pinned to 45ab8f4308)
Solutions
- Use the exact format WxH+X+Y, e.g. -crop 100x100+0+0.
- If calling the API, validate the parsed spec fields (width>0, height>0) after jtransform_parse_crop_spec returns nonzero.
- Quote the argument to prevent shell globbing/expansion of the '+' or 'x'.
- Test the crop string against the parser separately before bundling into a full jpegtran command.
Example fix
// before ./jpegtran -crop 100,100,0,0 in.jpg > out.jpg // after ./jpegtran -crop 100x100+0+0 in.jpg > out.jpg
Defensive patterns
Strategy: validation
Validate before calling
#include <ctype.h>
/* minimal WxH+X+Y validator matching jtransform_parse_crop_spec expectations */
int crop_spec_ok(const char *s) {
const char *p = s; char *end;
long w = strtol(p,&end,10); if (end==p||*end!='x'||w<=0) return 0; p=end+1;
long h = strtol(p,&end,10); if (end==p||h<=0) return 0; p=end;
if (*p!='+') return 0; p++;
long x = strtol(p,&end,10); if (end==p||x<0) return 0; p=end;
if (*p!='+') return 0; p++;
long y = strtol(p,&end,10); if (end==p||y<0) return 0; p=end;
return *p=='\0';
} Prevention
- Build crop strings in the exact WxH+X+Y form.
- Validate the spec before passing to jpegtran.
- Quote the argument to shield '+' and 'x' from the shell.
When it happens
Trigger: Passing a malformed crop spec such as -crop 100, -crop 100x, -crop x100+0+0, -crop 100x100-0-0, or any string jtransform_parse_crop_spec rejects. Also triggered by missing width/height or invalid delimiters.
Common situations: Constructing the crop string programmatically with a format bug, locale issues affecting 'x' parsing, or copy-pasting a spec from a tool that uses a different syntax.
Related errors
- %s: can only do one image transformation at a time
- %s: must name one input and one output file
- %s: crop dimensions exceed image dimensions %d x %d\n
- %s: sorry, image transformation was not compiled
- %s: sorry, arithmetic coding not supported
AI-assisted analysis of DrKLO/Telegram@45ab8f4308 (2026-08-14).
Data as JSON: /api/errors/001dbd1ad71e4c5c.
Report an issue: GitHub.