{"record":{"id":"ed4d9412c58b21bc","repo":"DrKLO/Telegram","slug":"s-can-t-read-from-s","errorCode":null,"errorMessage":"%s: can't read from %s\n","messagePattern":"(.+?): can't read from (.+?)\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"TMessagesProj/jni/mozjpeg/jpegtran.c","lineNumber":554,"sourceCode":"\n  /* Specify data source for decompression */\n  if (jpeg_c_int_param_supported(&dstinfo, JINT_COMPRESS_PROFILE) &&\n      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","sourceCodeStart":536,"sourceCodeEnd":572,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/mozjpeg/jpegtran.c#L536-L572","documentation":"During the memsrc read-loop (JCP_MAX_COMPRESSION mode), jpegtran calls JFREAD to fill the input buffer at jpegtran.c:551. If the read returns fewer than INPUT_BUF_SIZE bytes and ferror(fp) is true, a read I/O error occurred on the input file. The error message names the input file path from argv[file_index].","triggerScenarios":"Reading from a file on failing storage (bad sector, corrupted SD card). A truncated JPEG file that causes an I/O error mid-read. File on a network mount that drops the connection. Android external storage that is unmounted during processing.","commonSituations":"Processing a JPEG from removable storage (SD card, USB OTG). File on a FUSE mount that returns EIO. Concurrent unmount of the storage device. A partially-downloaded JPEG file on a bad cache.","solutions":["Copy the input JPEG to reliable internal storage before processing","Verify file integrity with a checksum before invoking jpegtran","Retry from a different copy of the file","Check device health if the error is persistent"],"exampleFix":"// before\njpegtran /sdcard/photos/input.jpg -outfile out.jpg\n\n// after\n// copy to internal storage first\ncopy_file(\"/sdcard/photos/input.jpg\", internal_tmp);\njpegtran internal_tmp -outfile out.jpg;","handlingStrategy":"validation","validationCode":"// Copy input from unreliable storage to internal storage before processing\nint stage_input_file(const char *src, const char *internal_dir, char *dst, size_t dst_len) {\n    snprintf(dst, dst_len, \"%s/jpegtran_input_%d.jpg\", internal_dir, getpid());\n    FILE *in = fopen(src, \"rb\");\n    if (!in) return -1;\n    FILE *out = fopen(dst, \"wb\");\n    if (!out) { fclose(in); return -1; }\n    char buf[8192]; size_t n;\n    while ((n = fread(buf, 1, sizeof(buf), in)) > 0) {\n        if (fwrite(buf, 1, n, out) != n) { fclose(in); fclose(out); return -1; }\n    }\n    int err = ferror(in);\n    fclose(in); fclose(out);\n    return err ? -1 : 0;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Copy input files from removable/network storage to local storage before processing","Verify file integrity with a checksum before invoking jpegtran","Avoid processing files directly from SD cards or network mounts"],"tags":["jpeg","jpegtran","file-io","io-error","max-compression"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}