{"record":{"id":"d3127662499018c7","repo":"DrKLO/Telegram","slug":"s-can-t-read-from-stdin","errorCode":null,"errorMessage":"%s: can't read from stdin\n","messagePattern":"(.+?): can't read from stdin\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"TMessagesProj/jni/mozjpeg/jpegtran.c","lineNumber":557,"sourceCode":"      jpeg_c_get_int_param(&dstinfo, JINT_COMPRESS_PROFILE)\n        == JCP_MAX_COMPRESSION)\n    memsrc = TRUE; /* needed to revert to original */\n#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)\n  if (memsrc) {\n    size_t nbytes;\n    do {\n      inbuffer = (unsigned char *)realloc(inbuffer, insize + INPUT_BUF_SIZE);\n      if (inbuffer == NULL) {\n        fprintf(stderr, \"%s: memory allocation failure\\n\", progname);\n        exit(EXIT_FAILURE);\n      }\n      nbytes = JFREAD(fp, &inbuffer[insize], INPUT_BUF_SIZE);\n      if (nbytes < INPUT_BUF_SIZE && ferror(fp)) {\n        if (file_index < argc)\n          fprintf(stderr, \"%s: can't read from %s\\n\", progname,\n                  argv[file_index]);\n        else\n          fprintf(stderr, \"%s: can't read from stdin\\n\", progname);\n      }\n      insize += (unsigned long)nbytes;\n    } while (nbytes == INPUT_BUF_SIZE);\n    jpeg_mem_src(&srcinfo, inbuffer, insize);\n  } else\n#endif\n  jpeg_stdio_src(&srcinfo, fp);\n\n  /* Enable saving of extra markers that we want to copy */\n  jcopy_markers_setup(&srcinfo, copyoption);\n\n  /* Read file header */\n  (void)jpeg_read_header(&srcinfo, TRUE);\n\n  /* Any space needed by a transform option must be requested before\n   * jpeg_read_coefficients so that memory allocation will be done right.\n   */\n#if TRANSFORMS_SUPPORTED","sourceCodeStart":539,"sourceCodeEnd":575,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/mozjpeg/jpegtran.c#L539-L575","documentation":"Same read-error condition as error 147, but fired when the input is stdin (file_index >= argc) rather than a named file. During the memsrc read-loop, JFREAD returns fewer than INPUT_BUF_SIZE bytes with ferror(fp) true on stdin. The message says 'can't read from stdin' instead of naming a file.","triggerScenarios":"Piping input through stdin (`cat file.jpg | jpegtran`) where the pipe breaks (upstream process crashes). Reading from a terminal that sends unexpected EOF. A redirected stdin from a file on failing storage.","commonSituations":"A piped command where the upstream `cat` or `curl` fails mid-stream. A broken pipe from a network download piped to jpegtran. Process substitution that fails.","solutions":["Write the input to a temp file first, then pass the file path instead of piping through stdin","Verify the piped input is complete before feeding it to jpegtran","Check the exit code of the upstream command in the pipe"],"exampleFix":"// before\ncurl http://example.com/img.jpg | jpegtran -outfile out.jpg\n\n// after\ncurl -o /tmp/input.jpg http://example.com/img.jpg\nif [ $? -eq 0 ]; then\n  jpegtran /tmp/input.jpg -outfile out.jpg\nfi","handlingStrategy":"validation","validationCode":"// Don't pipe; stage the input to a file first, then pass the path\nint stage_stdin_to_file(const char *internal_dir, char *dst, size_t dst_len) {\n    snprintf(dst, dst_len, \"%s/jpegtran_stdin_%d.jpg\", internal_dir, getpid());\n    FILE *out = fopen(dst, \"wb\");\n    if (!out) return -1;\n    char buf[8192]; size_t n;\n    while ((n = fread(buf, 1, sizeof(buf), stdin)) > 0)\n        if (fwrite(buf, 1, n, out) != n) { fclose(out); return -1; }\n    int err = ferror(stdin);\n    fclose(out);\n    return err ? -1 : 0;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid piping input through stdin; use a file path instead","If piping from a download, complete the download to a file first","Check the exit code of upstream commands in a pipeline before feeding to jpegtran"],"tags":["jpeg","jpegtran","file-io","io-error","stdin","max-compression"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}