DrKLO/Telegram · error

%s: can't open stdin

Error message

%s: can't open stdin

What it means

When no input file is specified on the command line, rdjpgcom defaults to reading from stdin. On platforms requiring USE_FDOPEN (to reopen stdin in binary mode), if fdopen fails the program reports it cannot open stdin and exits. This is a rare failure indicating the standard input file descriptor is unavailable or cannot be wrapped in a FILE stream.

Source

Thrown at TMessagesProj/jni/mozjpeg/rdjpgcom.c:497

  /* Open the input file. */
  /* Unix style: expect zero or one file name */
  if (argn < argc - 1) {
    fprintf(stderr, "%s: only one input file\n", progname);
    usage();
  }
  if (argn < argc) {
    if ((infile = fopen(argv[argn], READ_BINARY)) == NULL) {
      fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]);
      exit(EXIT_FAILURE);
    }
  } else {
    /* default input file is stdin */
#ifdef USE_SETMODE              /* need to hack file mode? */
    setmode(fileno(stdin), O_BINARY);
#endif
#ifdef USE_FDOPEN               /* need to re-open in binary mode? */
    if ((infile = fdopen(fileno(stdin), READ_BINARY)) == NULL) {
      fprintf(stderr, "%s: can't open stdin\n", progname);
      exit(EXIT_FAILURE);
    }
#else
    infile = stdin;
#endif
  }

  /* Scan the JPEG headers. */
  (void)scan_JPEG_header(verbose, raw);

  /* All done. */
  exit(EXIT_SUCCESS);
  return 0;                     /* suppress no-return-value warnings */
}

View on GitHub (pinned to 45ab8f4308)

Solutions

  1. Pass a file path explicitly instead of relying on stdin: rdjpgcom file.jpg.
  2. Ensure stdin is a valid open file descriptor before piping: rdjpgcom < file.jpg.
  3. Check that the calling environment has not closed fd 0 before invoking the program.

Example fix

# before
rdjpgcom  # stdin broken
# after
rdjpgcom file.jpg
Defensive patterns

Strategy: validation

Validate before calling

# Check that stdin is available, otherwise use a file argument
if [ ! -t 0 ] && [ -r /dev/stdin ]; then
  rdjpgcom < "$input_file"
else
  rdjpgcom "$input_file"
fi

Prevention

When it happens

Trigger: No file argument is passed and fdopen(fileno(stdin), READ_BINARY) returns NULL. This can happen if stdin file descriptor 0 has been closed, is invalid, or the system cannot allocate the FILE structure.

Common situations: Running rdjpgcom in a pipeline where stdin has been closed or redirected to /dev/null in a way that breaks fdopen; running in a sandboxed/container environment with restricted file descriptor allocation; process has already consumed or closed stdin before rdjpgcom starts.

Related errors


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