DrKLO/Telegram · error

%s: can't read qtable file

Error message

%s: can't read qtable file

What it means

cjpeg calls read_quant_tables() to load -qtables from a plain-ASCII file of 64 decimal integers per table (comments with # allowed, up to NUM_QUANT_TBLS tables). It returns FALSE if the file cannot be opened, contains too many tables, has invalid/non-numeric data, or non-numeric residue after a table. The wrapper prints this message and calls usage().

Source

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

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

#ifdef C_PROGRESSIVE_SUPPORTED
    if (simple_progressive)     /* process -progressive; -scans can override */
      jpeg_simple_progression(cinfo);

View on GitHub (pinned to 45ab8f4308)

Solutions

  1. Open the file in a text editor and confirm it is 1..NUM_QUANT_TBLS tables of exactly 64 integer values each, whitespace-separated, comments starting with #.
  2. Verify the path exists and is readable; check the error printed just before this line by read_quant_tables (e.g. 'Invalid table data', 'Too many tables', 'Non-numeric data').
  3. Regenerate the table file with a script that emits 64 ints per table to avoid off-by-one counts.

Example fix

# before: file has 63 values per table -> read_quant_tables fails
cjpeg -qtables bad.txt input.ppm > out.jpg
# after: ensure exactly 64 values per table
python3 -c "print(' '.join(['16']*64))" > good.txt
cjpeg -qtables good.txt input.ppm > out.jpg
Defensive patterns

Strategy: validation

Validate before calling

#!/bin/sh
# Validate a quant-table file: 64 ints per table, max NUM_QUANT_TBLS (4) tables
qfile="$1"
[ -r "$qfile" ] || { echo "qtable file unreadable: $qfile" >&2; exit 1; }
awk '
{ for (i=1;i<=NF;i++) if ($i !~ /^[-+]?[0-9]+$/) {print "non-numeric: "$i>"/dev/stderr"; exit 1} n+=NF }
END{ if (n==0 || n%64!=0 || n/64>4) {print "bad table count/values: "n>"/dev/stderr"; exit 1} }
' "$qfile" || exit 1
cjpeg -qtables "$qfile" in.ppm > out.jpg

Type guard

// n/a: file-content validation in the caller.

Try / catch

if ! cjpeg -qtables "$QFILE" in.ppm > out.jpg 2>/tmp/e; then
  grep -Eq "can't read qtable file|Invalid table data|Too many tables|Non-numeric data" /tmp/e && { echo "fix qtable file: $QFILE"; exit 1; }
fi

Prevention

When it happens

Trigger: Passing -qtables <file> where the file is missing, unreadable, contains fewer/more than 64 values per table, more than NUM_QUANT_TBLS tables, or any non-numeric token not part of a # comment.

Common situations: Hand-authored quant tables with formatting errors; binary files mistakenly passed as text quant tables; truncated downloads; line-ending or locale issues that inject unexpected characters; a wrong path pointing at a non-table file.

Related errors


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