{"record":{"id":"df4117557dda73d5","repo":"DrKLO/Telegram","slug":"s-only-one-input-file-df4117","errorCode":null,"errorMessage":"%s: only one input file\n","messagePattern":"(.+?): only one input file\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"TMessagesProj/jni/mozjpeg/jpegtran.c","lineNumber":487,"sourceCode":"  /* Must have either -outfile switch or explicit output file name */\n  if (outfilename == NULL) {\n    if (file_index != argc - 2) {\n      fprintf(stderr, \"%s: must name one input and one output file\\n\",\n              progname);\n      usage();\n    }\n    outfilename = argv[file_index + 1];\n  } else {\n    if (file_index != argc - 1) {\n      fprintf(stderr, \"%s: must name one input and one output file\\n\",\n              progname);\n      usage();\n    }\n  }\n#else\n  /* Unix style: expect zero or one file name */\n  if (file_index < argc - 1) {\n    fprintf(stderr, \"%s: only one input file\\n\", progname);\n    usage();\n  }\n#endif /* TWO_FILE_COMMANDLINE */\n\n  /* Open the input file. */\n  if (file_index < argc) {\n    if ((fp = fopen(argv[file_index], READ_BINARY)) == NULL) {\n      fprintf(stderr, \"%s: can't open %s for reading\\n\", progname,\n              argv[file_index]);\n      exit(EXIT_FAILURE);\n    }\n  } else {\n    /* default input file is stdin */\n    fp = read_stdin();\n  }\n\n  if (icc_filename != NULL) {\n    if ((icc_file = fopen(icc_filename, READ_BINARY)) == NULL) {","sourceCodeStart":469,"sourceCodeEnd":505,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/mozjpeg/jpegtran.c#L469-L505","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use `-outfile output.jpg` to specify the output path instead of a second positional arg: `jpegtran -outfile out.jpg in.jpg`","Pipe through stdin/stdout instead: `jpegtran < input.jpg > output.jpg`","If you need DOS-style two-file behavior, rebuild mozjpeg with -DTWO_FILE_COMMANDLINE"],"exampleFix":"// before\njpegtran input.jpg output.jpg\n\n// after\njpegtran -outfile output.jpg input.jpg","handlingStrategy":"validation","validationCode":"// Before calling jpegtran, count positional args (non-flag args)\n// In a JNI/shell wrapper:\nint count_positional(int argc, char **argv) {\n    int count = 0;\n    for (int i = 1; i < argc; i++) {\n        if (argv[i][0] != '-') count++;\n        else if (strcmp(argv[i], \"-outfile\") == 0) i++; // skip its value\n    }\n    return count;\n}\n// if count_positional > 1, use -outfile instead of positional output","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always use -outfile to specify output, keeping positional args to one (the input)","Quote shell variables to prevent glob expansion: \"$input\" not $input","In JNI wrappers, build the argv array programmatically with explicit -outfile"],"tags":["jpeg","jpegtran","cli-arguments","unix-style"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}