DrKLO/Telegram · error
%s: must name one input and one output file
Error message
%s: must name one input and one output file
What it means
Under TWO_FILE_COMMANDLINE, when no -outfile was given, jpegtran expects exactly one input and one output positional argument (file_index == argc - 2). If that invariant fails, jpegtran prints this message and calls usage() (which exits). The input is implicitly argv[file_index] and the output argv[file_index+1].
Source
Thrown at TMessagesProj/jni/mozjpeg/jpegtran.c:472
jpeg_create_compress(&dstinfo);
/* Scan command line to find file names.
* It is convenient to use just one switch-parsing routine, but the switch
* values read here are mostly ignored; we will rescan the switches after
* opening the input file. Also note that most of the switches affect the
* destination JPEG object, so we parse into that and then copy over what
* needs to affects the source too.
*/
file_index = parse_switches(&dstinfo, argc, argv, 0, FALSE);
jsrcerr.trace_level = jdsterr.trace_level;
srcinfo.mem->max_memory_to_use = dstinfo.mem->max_memory_to_use;
#ifdef TWO_FILE_COMMANDLINE
/* Must have either -outfile switch or explicit output file name */
if (outfilename == NULL) {
if (file_index != argc - 2) {
fprintf(stderr, "%s: must name one input and one output file\n",
progname);
usage();
}
outfilename = argv[file_index + 1];
} else {
if (file_index != argc - 1) {
fprintf(stderr, "%s: must name one input and one output file\n",
progname);
usage();
}
}
#else
/* Unix style: expect zero or one file name */
if (file_index < argc - 1) {
fprintf(stderr, "%s: only one input file\n", progname);
usage();
}
#endif /* TWO_FILE_COMMANDLINE */View on GitHub (pinned to 45ab8f4308)
Solutions
- Provide exactly two positional arguments: jpegtran in.jpg out.jpg.
- Use -outfile to name the output explicitly if positional parsing is ambiguous.
- Quote/guard against glob expansion: pass literal filenames, not unquoted patterns.
- Check argc in your wrapper before invoking jpegtran.
Example fix
// before ./jpegtran in.jpg // after ./jpegtran in.jpg out.jpg
Defensive patterns
Strategy: validation
Validate before calling
/* wrapper: ensure exactly two positional args when no -outfile */
int positional = 0, has_outfile = 0;
for (int i=1;i<argc;i++) {
if (strncmp(argv[i],"-outfile",8)==0||strncmp(argv[i],"-o",2)==0) has_outfile=1;
else if (argv[i][0]!='-') positional++;
}
if (!has_outfile && positional!=2) { fprintf(stderr,"need exactly INPUT OUTPUT\n"); exit(2); } Prevention
- Always supply exactly two positional files, or use -outfile.
- Quote globs to prevent unexpected multi-file expansion.
- Validate argument count in the wrapper.
When it happens
Trigger: Invoking jpegtran with zero, one, or three+ positional file arguments and no -outfile. Examples: jpegtran in.jpg (missing output), jpegtran in.jpg out.jpg extra.jpg, or jpegtran (no files).
Common situations: Forgetting the output argument, a shell glob expanding to multiple files in the input position, a quoting bug dropping an argument, or assuming stdout output is allowed (it is not under TWO_FILE_COMMANDLINE).
Related errors
- %s: can only do one image transformation at a time
- %s: bogus -crop argument '%s'
- %s: skip region exceeds image height %d\n
- %s: crop dimensions exceed image dimensions %d x %d\n
- %s: sorry, image transformation was not compiled
AI-assisted analysis of DrKLO/Telegram@45ab8f4308 (2026-08-14).
Data as JSON: /api/errors/5b4f0ef0bb6d2a91.
Report an issue: GitHub.