{"record":{"id":"f1af526174263055","repo":"DrKLO/Telegram","slug":"s-can-t-open-stdin-n","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/wrjpgcom.c","lineNumber":505,"sourceCode":"   * from stdin; in this case there MUST be an input JPEG file name.\n   */\n  if (comment_arg == NULL && comment_file == NULL && argn >= argc)\n    usage();\n\n  /* Open the input file. */\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  /* Open the output file. */\n#ifdef TWO_FILE_COMMANDLINE\n  /* Must have explicit output file name */\n  if (argn != argc - 2) {\n    fprintf(stderr, \"%s: must name one input and one output file\\n\", progname);\n    usage();\n  }\n  if ((outfile = fopen(argv[argn + 1], WRITE_BINARY)) == NULL) {\n    fprintf(stderr, \"%s: can't open %s\\n\", progname, argv[argn + 1]);\n    exit(EXIT_FAILURE);\n  }","sourceCodeStart":487,"sourceCodeEnd":523,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/mozjpeg/wrjpgcom.c#L487-L523","documentation":"When no input file name is given, wrjpgcom defaults to stdin and, if USE_FDOPEN is compiled in, re-opens stdin in binary mode via fdopen(fileno(stdin), READ_BINARY). If fdopen returns NULL the tool prints `%s: can't open stdin` and exits EXIT_FAILURE. This is a low-level stdio re-attach failure, not a missing-file error.","triggerScenarios":"Running wrjpgcom with stdin redirected but the descriptor unavailable/closed (e.g. stdin closed before exec, or fd 0 invalid), under a build that defines USE_FDOPEN.","commonSituations":"Invoking the tool from a context where fd 0 was closed or redirected to a bad descriptor, running under a sandbox/daemon that detached stdio, or a misconfigured JNI spawn that did not wire stdin.","solutions":["Provide an explicit input JPEG file name so stdin is not used.","Ensure fd 0 is a valid open descriptor before launching the tool.","Redirect stdin from a real file: `wrjpgcom ... < input.jpg`."],"exampleFix":"// before\nwrjpgcom -comment hi   # stdin closed in calling process\n// after\nwrjpgcom -comment hi input.jpg","handlingStrategy":"validation","validationCode":"#include <unistd.h>\n/* ensure stdin (fd 0) is valid before relying on default input */\nif (isatty(0) == 0 && fcntl(0, F_GETFD) == -1) {\n    /* stdin not usable; require an explicit input file */\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass an explicit input JPEG instead of relying on stdin.","Redirect stdin from a real file when piping.","Do not launch wrjpgcom with fd 0 closed."],"tags":["cli","jpeg","mozjpeg","wrjpgcom","stdio","stdin","environment"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}