DrKLO/Telegram · error

%s: can't set quality ratings

Error message

%s: can't set quality ratings

What it means

cjpeg calls set_quality_ratings() to parse the -quality argument (format N[,N,...], one value per quant table slot, last replicated). The function returns FALSE if sscanf fails to read a float, or if the separator after a value is not a comma. The wrapper then prints this message and calls usage().

Source

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

      jpeg_c_set_bool_param(cinfo, JBOOLEAN_OVERSHOOT_DERINGING, FALSE);

	} else if (keymatch(arg, "nojfif", 6)) {
      cinfo->write_JFIF_header = 0;
    } else {
      fprintf(stderr, "%s: unknown option '%s'\n", progname, arg);
      usage();                  /* bogus switch */
    }
  }

  /* Post-switch-scanning cleanup */

  if (for_real) {

    /* Set quantization tables for selected quality. */
    /* Some or all may be overridden if -qtables is present. */
    if (qualityarg != NULL)     /* process -quality if it was present */
      if (! set_quality_ratings(cinfo, qualityarg, force_baseline)) {
        fprintf(stderr, "%s: can't set quality ratings\n", progname);
        usage();
      }

    if (qtablefile != NULL)     /* process -qtables if it was present */
      if (! read_quant_tables(cinfo, qtablefile, force_baseline)) {
        fprintf(stderr, "%s: can't read qtable file\n", progname);
        usage();
      }

    if (qslotsarg != NULL)      /* process -qslots if it was present */
      if (!set_quant_slots(cinfo, qslotsarg))
        usage();

    /* set_quality_ratings sets default subsampling, so the explicit
       subsampling must be set after it */
    if (samplearg != NULL)      /* process -sample if it was present */
      if (! set_sample_factors(cinfo, samplearg)) {
        fprintf(stderr, "%s: can't set sample factors\n", progname);

View on GitHub (pinned to 45ab8f4308)

Solutions

  1. Use the documented format: a single number or a comma-separated list with no trailing comma, e.g. -quality 90 or -quality 80,90,85.
  2. If the value comes from a variable, validate it matches ^[0-9.]+(,[0-9.]+)*$ before passing it.
  3. Avoid trailing separators and non-comma delimiters (semicolons, slashes, spaces).

Example fix

# before
cjpeg -quality 75;90 input.ppm > out.jpg
# after
cjpeg -quality 75,90 input.ppm > out.jpg
Defensive patterns

Strategy: validation

Validate before calling

#!/bin/sh
# Validate -quality value format: N[,N,...] floats
QUALITY="$1"
printf '%s' "$QUALITY" | grep -Eq '^[0-9]+(\.[0-9]+)?(,[0-9]+(\.[0-9]+)?)*$' || { echo 'bad -quality format' >&2; exit 1; }
cjpeg -quality "$QUALITY" in.ppm > out.jpg

Type guard

// n/a: string-format validation in the caller.

Try / catch

if ! cjpeg -quality "$QUALITY" in.ppm > out.jpg 2>/tmp/e; then
  grep -q "can't set quality ratings" /tmp/e && { echo 'fix -quality format (N[,N,...])'; exit 1; }
fi

Prevention

When it happens

Trigger: Passing -quality with a malformed value: empty string, non-numeric token, a separator other than comma (e.g. -quality 75;90 or -quality 75/90), or a trailing comma with no following number that breaks the per-slot sscanf/separator loop.

Common situations: Quoting bugs that pass an empty -quality; config files that emit the wrong delimiter; localized environments where a comma is interpreted differently; copying a quality spec from documentation that used a different separator.

Related errors


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