DrKLO/Telegram · error
%s: can't read ICC profile from %s
Error message
%s: can't read ICC profile from %s
What it means
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.
Source
Thrown at TMessagesProj/jni/mozjpeg/cjpeg.c:779
if (icc_filename != NULL) {
if ((icc_file = fopen(icc_filename, READ_BINARY)) == NULL) {
fprintf(stderr, "%s: can't open %s\n", progname, icc_filename);
exit(EXIT_FAILURE);
}
if (fseek(icc_file, 0, SEEK_END) < 0 ||
(icc_len = ftell(icc_file)) < 1 ||
fseek(icc_file, 0, SEEK_SET) < 0) {
fprintf(stderr, "%s: can't determine size of %s\n", progname,
icc_filename);
exit(EXIT_FAILURE);
}
if ((icc_profile = (JOCTET *)malloc(icc_len)) == NULL) {
fprintf(stderr, "%s: can't allocate memory for ICC profile\n", progname);
fclose(icc_file);
exit(EXIT_FAILURE);
}
if (fread(icc_profile, icc_len, 1, icc_file) < 1) {
fprintf(stderr, "%s: can't read ICC profile from %s\n", progname,
icc_filename);
free(icc_profile);
fclose(icc_file);
exit(EXIT_FAILURE);
}
fclose(icc_file);
}
#ifdef PROGRESS_REPORT
start_progress_monitor((j_common_ptr)&cinfo, &progress);
#endif
/* Figure out the input file format, and set up to read it. */
src_mgr = select_file_type(&cinfo, input_file);
src_mgr->input_file = input_file;
/* Read the input file header to obtain file size & colorspace. */
(*src_mgr->start_input) (&cinfo, src_mgr);View on GitHub (pinned to 45ab8f4308)
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.
Example fix
# before: file truncated concurrently / unreliable read cjpeg -icc /netmount/profile.icc in.ppm out.jpg # after: copy to stable local path install -m 0644 /netmount/profile.icc /tmp/profile.icc cjpeg -icc /tmp/profile.icc in.ppm out.jpg
Defensive patterns
Strategy: validation
Validate before calling
#!/bin/sh
ICC="$1"
# Ensure file is stable and fully readable: copy to local tmp and checksum
TMP="$(mktemp)"; cp -- "$ICC" "$TMP" || { echo 'cannot stage ICC file' >&2; exit 1; }
[ "$(stat -c%s "$TMP")" -ge 1 ] || { echo 'staged ICC empty' >&2; rm -f "$TMP"; exit 1; }
cjpeg -icc "$TMP" in.ppm out.jpg; rc=$?; rm -f "$TMP"; exit $rc Type guard
// n/a: filesystem integrity check in the caller.
Try / catch
if ! cjpeg -icc "$ICC" in.ppm out.jpg 2>/tmp/e; then
grep -q "can't read ICC profile" /tmp/e && { echo "ICC read failed (truncated/I/O error): $ICC" >&2; exit 1; }
fi Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- %s: can't determine size of %s
- %s: can't open %s
- %s: can't allocate memory for ICC profile
- %s: sorry, arithmetic coding not supported
- %s: missing argument for dct
AI-assisted analysis of DrKLO/Telegram@45ab8f4308 (2026-08-14).
Data as JSON: /api/errors/0d8175f4503ce9b5.
Report an issue: GitHub.