{"record":{"id":"c3d1f9a3830bfd86","repo":"DrKLO/Telegram","slug":"s-can-t-read-icc-profile-from-s-c3d1f9","errorCode":null,"errorMessage":"%s: can't read ICC profile from %s\n","messagePattern":"(.+?): can't read ICC profile from (.+?)\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"TMessagesProj/jni/mozjpeg/jpegtran.c","lineNumber":522,"sourceCode":"  if (icc_filename != NULL) {\n    if ((icc_file = fopen(icc_filename, READ_BINARY)) == NULL) {\n      fprintf(stderr, \"%s: can't open %s\\n\", progname, icc_filename);\n      exit(EXIT_FAILURE);\n    }\n    if (fseek(icc_file, 0, SEEK_END) < 0 ||\n        (icc_len = ftell(icc_file)) < 1 ||\n        fseek(icc_file, 0, SEEK_SET) < 0) {\n      fprintf(stderr, \"%s: can't determine size of %s\\n\", progname,\n              icc_filename);\n      exit(EXIT_FAILURE);\n    }\n    if ((icc_profile = (JOCTET *)malloc(icc_len)) == NULL) {\n      fprintf(stderr, \"%s: can't allocate memory for ICC profile\\n\", progname);\n      fclose(icc_file);\n      exit(EXIT_FAILURE);\n    }\n    if (fread(icc_profile, icc_len, 1, icc_file) < 1) {\n      fprintf(stderr, \"%s: can't read ICC profile from %s\\n\", progname,\n              icc_filename);\n      free(icc_profile);\n      fclose(icc_file);\n      exit(EXIT_FAILURE);\n    }\n    fclose(icc_file);\n    if (copyoption == JCOPYOPT_ALL)\n      copyoption = JCOPYOPT_ALL_EXCEPT_ICC;\n  }\n\n#ifdef PROGRESS_REPORT\n  start_progress_monitor((j_common_ptr)&dstinfo, &progress);\n#endif\n\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)","sourceCodeStart":504,"sourceCodeEnd":540,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/mozjpeg/jpegtran.c#L504-L540","documentation":"After allocating the ICC buffer, jpegtran reads the profile data with fread(icc_profile, icc_len, 1, icc_file) at jpegtran.c:521. If fread returns less than 1 (fewer than icc_len bytes read), the read failed. This can happen if the file shrank between the size determination and the read, or there is an I/O error.","triggerScenarios":"The ICC file was truncated or modified between the fseek/ftell and the fread call. A filesystem error during read. The file is on a failing storage device. A race condition where another process truncates the file concurrently.","commonSituations":"Temp ICC file on Android external storage that gets unmounted. File on network storage with a dropped connection. Concurrent process writes/truncates the ICC file while jpegtran reads it.","solutions":["Copy the ICC profile to a stable local temp file and use that path","Ensure no other process writes to or truncates the ICC file while jpegtran runs","Verify file integrity (checksum) before passing it"],"exampleFix":"// before\n// icc_path shared, may be truncated by another process\n\n// after\n// copy to exclusive temp file\nchar tmp[256];\nsnprintf(tmp, sizeof(tmp), \"%s/icc_%d.tmp\", app_internal_dir, getpid());\ncopy_file(icc_path, tmp);\n// pass tmp to jpegtran -icc, delete after","handlingStrategy":"validation","validationCode":"// Copy ICC file to a private temp file to prevent concurrent modification\nint stage_icc_file(const char *src, char *tmp, size_t tmp_len) {\n    snprintf(tmp, tmp_len, \"/tmp/icc_%d.icc\", getpid());\n    FILE *in = fopen(src, \"rb\");\n    if (!in) return -1;\n    FILE *out = fopen(tmp, \"wb\");\n    if (!out) { fclose(in); return -1; }\n    char buf[4096]; 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    fclose(in); fclose(out);\n    return 0;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Copy the ICC profile to a private temp file before passing it to jpegtran","Ensure no other process writes to or truncates the ICC file during processing","Verify file integrity with a checksum before use"],"tags":["jpeg","jpegtran","icc-profile","file-io","race-condition"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}