DrKLO/Telegram · error

%s: only one input file

Error message

%s: only one input file

What it means

jpegtran in Unix-style mode (TWO_FILE_COMMANDLINE undefined) accepts zero or one positional input filename. The check at jpegtran.c:486 verifies file_index < argc - 1, meaning more than one positional argument remained after option parsing. This fires when the user passes multiple filenames in a build configured for Unix-style single-file invocation.

Source

Thrown at TMessagesProj/jni/mozjpeg/jpegtran.c:487

  /* 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 */

  /* Open the input file. */
  if (file_index < argc) {
    if ((fp = fopen(argv[file_index], READ_BINARY)) == NULL) {
      fprintf(stderr, "%s: can't open %s for reading\n", progname,
              argv[file_index]);
      exit(EXIT_FAILURE);
    }
  } else {
    /* default input file is stdin */
    fp = read_stdin();
  }

  if (icc_filename != NULL) {
    if ((icc_file = fopen(icc_filename, READ_BINARY)) == NULL) {

View on GitHub (pinned to 45ab8f4308)

Solutions

  1. Use `-outfile output.jpg` to specify the output path instead of a second positional arg: `jpegtran -outfile out.jpg in.jpg`
  2. Pipe through stdin/stdout instead: `jpegtran < input.jpg > output.jpg`
  3. If you need DOS-style two-file behavior, rebuild mozjpeg with -DTWO_FILE_COMMANDLINE

Example fix

// before
jpegtran input.jpg output.jpg

// after
jpegtran -outfile output.jpg input.jpg
Defensive patterns

Strategy: validation

Validate before calling

// Before calling jpegtran, count positional args (non-flag args)
// In a JNI/shell wrapper:
int count_positional(int argc, char **argv) {
    int count = 0;
    for (int i = 1; i < argc; i++) {
        if (argv[i][0] != '-') count++;
        else if (strcmp(argv[i], "-outfile") == 0) i++; // skip its value
    }
    return count;
}
// if count_positional > 1, use -outfile instead of positional output

Prevention

When it happens

Trigger: Invoking jpegtran with two or more positional filenames, e.g. `jpegtran input.jpg output.jpg`, when the binary was compiled without TWO_FILE_COMMANDLINE. Also triggered by an unquoted glob expanding to multiple files.

Common situations: User assumes jpegtran takes input and output as positional args (DOS/Windows style) but the build uses Unix conventions. A shell glob like `jpegtran *.jpg` expands to many args. A wrapper script passes both input and output positionally.

Related errors


AI-assisted analysis of DrKLO/Telegram@45ab8f4308 (2026-08-14). Data as JSON: /api/errors/df4117557dda73d5. Report an issue: GitHub.