DrKLO/Telegram · error

Can't open table file %s

Error message

Can't open table file %s

What it means

The read_quant_tables function attempts to open the quantization table file specified by the -qtables filename argument. If fopen fails (returns NULL), the file does not exist or is not accessible. The function returns FALSE, signaling failure to the cjpeg caller. This is part of mozjpeg's custom quantization table loading feature, where tables are stored as plain ASCII decimal values.

Source

Thrown at TMessagesProj/jni/mozjpeg/rdswitch.c:98

GLOBAL(boolean)
read_quant_tables(j_compress_ptr cinfo, char *filename, boolean force_baseline)
/* Read a set of quantization tables from the specified file.
 * The file is plain ASCII text: decimal numbers with whitespace between.
 * Comments preceded by '#' may be included in the file.
 * There may be one to NUM_QUANT_TBLS tables in the file, each of 64 values.
 * The tables are implicitly numbered 0,1,etc.
 * NOTE: does not affect the qslots mapping, which will default to selecting
 * table 0 for luminance (or primary) components, 1 for chrominance components.
 * You must use -qslots if you want a different component->table mapping.
 */
{
  FILE *fp;
  int tblno, i, termchar;
  long val;
  unsigned int table[DCTSIZE2];

  if ((fp = fopen(filename, "r")) == NULL) {
    fprintf(stderr, "Can't open table file %s\n", filename);
    return FALSE;
  }
  tblno = 0;

  while (read_text_integer(fp, &val, &termchar)) { /* read 1st element of table */
    if (tblno >= NUM_QUANT_TBLS) {
      fprintf(stderr, "Too many tables in file %s\n", filename);
      fclose(fp);
      return FALSE;
    }
    table[0] = (unsigned int) val;
    for (i = 1; i < DCTSIZE2; i++) {
      if (! read_text_integer(fp, &val, &termchar)) {
        fprintf(stderr, "Invalid table data in file %s\n", filename);
        fclose(fp);
        return FALSE;
      }
      table[i] = (unsigned int) val;

View on GitHub (pinned to 45ab8f4308)

Solutions

  1. Verify the table file exists and is readable: test -f <file> and test -r <file>.
  2. Check the path for typos and use an absolute path if uncertain about the working directory.
  3. Generate the quantization table file if it does not exist (it should contain 64 integers per table in plain text).

Example fix

# before
cjpeg -qtables nonexistent.qtl image.bmp > out.jpg
# after
cjpeg -qtables /path/to/quant_tables.qtl image.bmp > out.jpg
Defensive patterns

Strategy: validation

Validate before calling

// In C: check file accessibility before calling read_quant_tables
#include <unistd.h>
if (access(filename, R_OK) != 0) {
  fprintf(stderr, "Table file %s is not readable\n", filename);
  return FALSE;
}
return read_quant_tables(cinfo, filename, force_baseline);

Prevention

When it happens

Trigger: Calling cjpeg with -qtables <file> where <file> does not exist, is unreadable, or is a directory. The fopen(filename, 'r') check at the entry of read_quant_tables returns NULL.

Common situations: Typo in the quantization table filename; relative path from the wrong working directory; the table file was not generated or deployed; permissions issue on the table file; pointing to a directory instead of a file.

Related errors


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