{"record":{"id":"ff7b22fe87e08a89","repo":"DrKLO/Telegram","slug":"s-can-t-open-stdin","errorCode":null,"errorMessage":"%s: can't open stdin\n","messagePattern":"(.+?): can't open stdin\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"TMessagesProj/jni/mozjpeg/rdjpgcom.c","lineNumber":497,"sourceCode":"  /* Open the input file. */\n  /* Unix style: expect zero or one file name */\n  if (argn < argc - 1) {\n    fprintf(stderr, \"%s: only one input file\\n\", progname);\n    usage();\n  }\n  if (argn < argc) {\n    if ((infile = fopen(argv[argn], READ_BINARY)) == NULL) {\n      fprintf(stderr, \"%s: can't open %s\\n\", progname, argv[argn]);\n      exit(EXIT_FAILURE);\n    }\n  } else {\n    /* default input file is stdin */\n#ifdef USE_SETMODE              /* need to hack file mode? */\n    setmode(fileno(stdin), O_BINARY);\n#endif\n#ifdef USE_FDOPEN               /* need to re-open in binary mode? */\n    if ((infile = fdopen(fileno(stdin), READ_BINARY)) == NULL) {\n      fprintf(stderr, \"%s: can't open stdin\\n\", progname);\n      exit(EXIT_FAILURE);\n    }\n#else\n    infile = stdin;\n#endif\n  }\n\n  /* Scan the JPEG headers. */\n  (void)scan_JPEG_header(verbose, raw);\n\n  /* All done. */\n  exit(EXIT_SUCCESS);\n  return 0;                     /* suppress no-return-value warnings */\n}\n","sourceCodeStart":479,"sourceCodeEnd":512,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/mozjpeg/rdjpgcom.c#L479-L512","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass a file path explicitly instead of relying on stdin: rdjpgcom file.jpg.","Ensure stdin is a valid open file descriptor before piping: rdjpgcom < file.jpg.","Check that the calling environment has not closed fd 0 before invoking the program."],"exampleFix":"# before\nrdjpgcom  # stdin broken\n# after\nrdjpgcom file.jpg","handlingStrategy":"validation","validationCode":"# Check that stdin is available, otherwise use a file argument\nif [ ! -t 0 ] && [ -r /dev/stdin ]; then\n  rdjpgcom < \"$input_file\"\nelse\n  rdjpgcom \"$input_file\"\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass an explicit file path to avoid stdin-related failures.","Avoid closing fd 0 in the calling process before invoking rdjpgcom.","In pipelines, ensure the upstream process has not exited and closed stdout."],"tags":["filesystem","stdin","cli","mozjpeg"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}