DrKLO/Telegram · error

%s: can't determine size of %s

Error message

%s: can't determine size of %s

What it means

After opening the ICC file, cjpeg seeks to the end (fseek SEEK_END), calls ftell to get the size, and seeks back (fseek SEEK_SET). If any seek fails or ftell returns a value < 1 (empty file), it prints this message and exits EXIT_FAILURE. The %s is icc_filename.

Source

Thrown at TMessagesProj/jni/mozjpeg/cjpeg.c:769

  if (outfilename != NULL) {
    if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) {
      fprintf(stderr, "%s: can't open %s\n", progname, outfilename);
      exit(EXIT_FAILURE);
    }
  } else if (!memdst) {
    /* default output file is stdout */
    output_file = write_stdout();
  }

  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);
  }

View on GitHub (pinned to 45ab8f4308)

Solutions

  1. Ensure the ICC file is a regular, non-empty file.
  2. Do not pipe or use special devices for -icc; copy the profile to a real file first.
  3. Re-download/restore a valid, complete ICC profile if the size is zero.

Example fix

# before: empty or piped icc
cat profile.icc | cjpeg -icc /dev/stdin in.ppm out.jpg
# after: regular non-empty file
cjpeg -icc profile.icc in.ppm out.jpg
Defensive patterns

Strategy: validation

Validate before calling

#!/bin/sh
ICC="$1"
[ -f "$ICC" ] || { echo "not a regular file: $ICC" >&2; exit 1; }
[ -c "$ICC" ] && { echo 'icc must be a regular (seekable) file, not a pipe/device' >&2; exit 1; }
size=$(stat -c%s "$ICC" 2>/dev/null || stat -f%z "$ICC")
[ "$size" -ge 1 ] 2>/dev/null || { echo "ICC file empty or size unknown: $ICC" >&2; exit 1; }
cjpeg -icc "$ICC" in.ppm out.jpg

Type guard

// n/a: filesystem precondition check in the caller.

Try / catch

if ! cjpeg -icc "$ICC" in.ppm out.jpg 2>/tmp/e; then
  grep -q "can't determine size" /tmp/e && { echo "ICC not seekable or empty: $ICC" >&2; exit 1; }
fi

Prevention

When it happens

Trigger: The ICC file is empty (zero bytes / size < 1), or the file descriptor is non-seekable (e.g. a pipe, FIFO, or special device passed as -icc), causing fseek/ftell to fail.

Common situations: Passing a pipe or /dev/stdin as the -icc source; a truncated/empty download of a profile; a symlink pointing at an empty target; a file on a filesystem that reports size incorrectly.

Related errors


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