DrKLO/Telegram · warning

%s: can't read from %s\n

Error message

%s: can't read from %s\n

What it means

During in-memory source loading, a JFREAD of the input FILE returned fewer than INPUT_BUF_SIZE bytes AND ferror() is set, signalling an I/O read failure (not a clean EOF). The error names the offending input file path. Note the loop still continues; this is diagnostic, not an exit.

Source

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

#ifdef PROGRESS_REPORT
  start_progress_monitor((j_common_ptr)&cinfo, &progress);
#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);

View on GitHub (pinned to 45ab8f4308)

Solutions

  1. Verify the source file integrity (cmp, md5sum against a known copy) before decoding.
  2. Remount or restore the storage and re-run; transient I/O errors are common on flaky mounts.
  3. Copy the input to local stable storage first, then decode the copy.
  4. If using a pipe/FIFO, ensure the producer writes the full stream to completion.

Example fix

// before: decode directly from flaky mount
./djpeg -memsrc /mnt/net/in.jpg > out.ppm
// after: stage locally first
cp /mnt/net/in.jpg /tmp/in.jpg && ./djpeg -memsrc /tmp/in.jpg > out.ppm
Defensive patterns

Strategy: validation

Validate before calling

#include <sys/stat.h>
/* verify file integrity hint: non-zero size, readable */
int input_looks_ok(const char *p) {
  struct stat st;
  return stat(p,&st)==0 && S_ISREG(st.st_mode) && st.st_size>0 && access(p,R_OK)==0;
}

Prevention

When it happens

Trigger: Reading from a file on a failing/unmounted filesystem, a network mount that drops, a truncated file on a hot-unplugged device, or any condition where the FILE stream sets its error indicator. Emitted only when file_index < argc (explicit filename), inside the memsrc read loop.

Common situations: Input on removable storage removed mid-read, NFS/SMB mount timeout, corrupted storage, or a pipe/FIFO closed early by the producer. The message is advisory: decompression proceeds with whatever was read and may fail later.

Related errors


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