{"record":{"id":"79293ee87b388fbf","repo":"DrKLO/Telegram","slug":"s-can-t-read-from-stdin-n","errorCode":null,"errorMessage":"%s: can't read from stdin\\n","messagePattern":"(.+?): can't read from stdin\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"TMessagesProj/jni/mozjpeg/djpeg.c","lineNumber":626,"sourceCode":"#endif\n\n  /* Specify data source for decompression */\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(input_file, &inbuffer[insize], INPUT_BUF_SIZE);\n      if (nbytes < INPUT_BUF_SIZE && ferror(input_file)) {\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    fprintf(stderr, \"Compressed size:  %lu bytes\\n\", insize);\n    jpeg_mem_src(&cinfo, inbuffer, insize);\n  } else\n#endif\n    jpeg_stdio_src(&cinfo, input_file);\n\n  /* Read file header, set default decompression parameters */\n  (void)jpeg_read_header(&cinfo, TRUE);\n\n  /* Adjust default decompression parameters by re-parsing the options */\n  file_index = parse_switches(&cinfo, argc, argv, 0, TRUE);\n\n  /* Initialize the output module now to let it override any crucial\n   * option settings (for instance, GIF wants to force color quantization).\n   */","sourceCodeStart":608,"sourceCodeEnd":644,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/mozjpeg/djpeg.c#L608-L644","documentation":"Same I/O read-failure condition as error 123, but reported when the input is stdin rather than a named file. Emitted inside the memsrc read loop when JFREAD(stdin) is short and ferror(stdin) is set. Advisory only; the loop continues.","triggerScenarios":"Piping into djpeg -memsrc where the upstream process terminates or closes the pipe before EOF, a broken network redirect feeding stdin, or a terminal stdin that signals error. Triggered specifically when file_index >= argc (no filename given, reading stdin).","commonSituations":"cat in.jpg | djpeg -memsrc where cat is killed early, curl ... | djpeg with a connection drop, or running djpeg -memsrc interactively with no piped input and sending a malformed signal.","solutions":["Ensure the producer of the pipe writes the complete file and exits cleanly before djpeg reads EOF.","For network sources, download to a temp file first, then pipe/decode, to isolate transient errors.","Validate the stream size matches the source Content-Length before decoding.","Avoid -memsrc over pipes; prefer stream source which tolerates incremental reads better."],"exampleFix":"// before: pipe can break mid-stream\ncurl http://h/in.jpg | ./djpeg -memsrc > out.ppm\n// after: download fully, then decode\ncurl -s http://h/in.jpg -o /tmp/in.jpg && ./djpeg -memsrc /tmp/in.jpg > out.ppm","handlingStrategy":"validation","validationCode":"/* before piping into djpeg -memsrc, confirm the producer can deliver full size */\n/* e.g. download to a temp file and stat its size against Content-Length */\nsize_t expected = resp.content_length;\nstruct stat st; stat(tmp, &st);\nif ((size_t)st.st_size != expected) { /* abort, do not pipe */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid -memsrc over pipes; use stream source.","For curl|djpeg, download fully first.","Ensure the producer exits cleanly so stdin sees a true EOF."],"tags":["file-io","djpeg","memsrc","stdin","mozjpeg"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}