DrKLO/Telegram · warning

: can't read from stdin\n

Error message

%s: can't read from stdin\n

What it means

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.

Solutions

  1. Ensure the producer of the pipe writes the complete file and exits cleanly before djpeg reads EOF.
  2. For network sources, download to a temp file first, then pipe/decode, to isolate transient errors.
  3. Validate the stream size matches the source Content-Length before decoding.
  4. Avoid -memsrc over pipes; prefer stream source which tolerates incremental reads better.

Example fix

// before: pipe can break mid-stream
curl http://h/in.jpg | ./djpeg -memsrc > out.ppm
// after: download fully, then decode
curl -s http://h/in.jpg -o /tmp/in.jpg && ./djpeg -memsrc /tmp/in.jpg > out.ppm
Defensive patterns

Strategy: validation

Validate before calling

/* before piping into djpeg -memsrc, confirm the producer can deliver full size */
/* e.g. download to a temp file and stat its size against Content-Length */
size_t expected = resp.content_length;
struct stat st; stat(tmp, &st);
if ((size_t)st.st_size != expected) { /* abort, do not pipe */ }

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


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

Appendix: source

Thrown at TMessagesProj/jni/mozjpeg/djpeg.c:626

#endif

  /* Specify data source for decompression */
#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
  if (memsrc) {
    size_t nbytes;
    do {
      inbuffer = (unsigned char *)realloc(inbuffer, insize + INPUT_BUF_SIZE);
      if (inbuffer == NULL) {
        fprintf(stderr, "%s: memory allocation failure\n", progname);
        exit(EXIT_FAILURE);
      }
      nbytes = JFREAD(input_file, &inbuffer[insize], INPUT_BUF_SIZE);
      if (nbytes < INPUT_BUF_SIZE && ferror(input_file)) {
        if (file_index < argc)
          fprintf(stderr, "%s: can't read from %s\n", progname,
                  argv[file_index]);
        else
          fprintf(stderr, "%s: can't read from stdin\n", progname);
      }
      insize += (unsigned long)nbytes;
    } while (nbytes == INPUT_BUF_SIZE);
    fprintf(stderr, "Compressed size:  %lu bytes\n", insize);
    jpeg_mem_src(&cinfo, inbuffer, insize);
  } else
#endif
    jpeg_stdio_src(&cinfo, input_file);

  /* Read file header, set default decompression parameters */
  (void)jpeg_read_header(&cinfo, TRUE);

  /* Adjust default decompression parameters by re-parsing the options */
  file_index = parse_switches(&cinfo, argc, argv, 0, TRUE);

  /* Initialize the output module now to let it override any crucial
   * option settings (for instance, GIF wants to force color quantization).
   */

View on GitHub (pinned to 45ab8f4308)