{"record":{"id":"0d8175f4503ce9b5","repo":"DrKLO/Telegram","slug":"s-can-t-read-icc-profile-from-s","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/cjpeg.c","lineNumber":779,"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  }\n\n#ifdef PROGRESS_REPORT\n  start_progress_monitor((j_common_ptr)&cinfo, &progress);\n#endif\n\n  /* Figure out the input file format, and set up to read it. */\n  src_mgr = select_file_type(&cinfo, input_file);\n  src_mgr->input_file = input_file;\n\n  /* Read the input file header to obtain file size & colorspace. */\n  (*src_mgr->start_input) (&cinfo, src_mgr);","sourceCodeStart":761,"sourceCodeEnd":797,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/mozjpeg/cjpeg.c#L761-L797","documentation":"After allocating the ICC buffer, cjpeg reads icc_len bytes with fread(icc_profile, icc_len, 1, icc_file). If fread returns < 1 (read error or premature EOF where fewer than icc_len bytes could be read), it prints this message, frees the buffer, closes the file, and exits EXIT_FAILURE.","triggerScenarios":"The file shrank between the ftell size probe and the read (TOCTOU), a read I/O error occurred, or the reported size did not match actual readable bytes (e.g. text-mode translation on some platforms, or a file on an unreliable mount).","commonSituations":"The file being modified/truncated concurrently; flaky storage (SD card, network mount); platform text-mode CR/LF translation shrinking effective bytes (on systems where READ_BINARY is not truly binary); corrupted download.","solutions":["Use a stable, complete, local copy of the ICC profile and ensure nothing writes to it during encoding.","Open files in binary mode to avoid translation issues; verify integrity with a checksum (e.g. sha256) before encoding.","If storage is unreliable, copy the profile to local tmp storage first and pass that path."],"exampleFix":"# before: file truncated concurrently / unreliable read\ncjpeg -icc /netmount/profile.icc in.ppm out.jpg\n# after: copy to stable local path\ninstall -m 0644 /netmount/profile.icc /tmp/profile.icc\ncjpeg -icc /tmp/profile.icc in.ppm out.jpg","handlingStrategy":"validation","validationCode":"#!/bin/sh\nICC=\"$1\"\n# Ensure file is stable and fully readable: copy to local tmp and checksum\nTMP=\"$(mktemp)\"; cp -- \"$ICC\" \"$TMP\" || { echo 'cannot stage ICC file' >&2; exit 1; }\n[ \"$(stat -c%s \"$TMP\")\" -ge 1 ] || { echo 'staged ICC empty' >&2; rm -f \"$TMP\"; exit 1; }\ncjpeg -icc \"$TMP\" in.ppm out.jpg; rc=$?; rm -f \"$TMP\"; exit $rc","typeGuard":"// n/a: filesystem integrity check in the caller.","tryCatchPattern":"if ! cjpeg -icc \"$ICC\" in.ppm out.jpg 2>/tmp/e; then\n  grep -q \"can't read ICC profile\" /tmp/e && { echo \"ICC read failed (truncated/I/O error): $ICC\" >&2; exit 1; }\nfi","preventionTips":["Stage the ICC profile to reliable local storage before encoding.","Verify a checksum (sha256) of the profile to detect truncation/corruption.","Avoid network mounts or concurrent writers on the ICC file during read."],"tags":["mozjpeg","cjpeg","filesystem","fread","icc-profile"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}