DrKLO/Telegram · error

Too many tables in file %s

Error message

Too many tables in file %s

What it means

read_quant_tables reads quantization tables from a text file where each table has exactly 64 values (DCTSIZE2 = 64). The file may contain up to NUM_QUANT_TBLS tables (typically 4). If more tables are found (tblno exceeds NUM_QUANT_TBLS), the function reports an error, closes the file, and returns FALSE. This prevents writing past the available quantization table slots.

Source

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

 * 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;
    }
#if JPEG_LIB_VERSION >= 70
    jpeg_add_quant_table(cinfo, tblno, table, cinfo->q_scale_factor[tblno],
                         force_baseline);
#else
    jpeg_add_quant_table(cinfo, tblno, table, q_scale_factor[tblno],
                         force_baseline);

View on GitHub (pinned to 45ab8f4308)

Solutions

  1. Reduce the number of tables in the file to at most NUM_QUANT_TBLS (typically 4). Each table is 64 comma/space-separated integers.
  2. Remove extra tables from the file and keep only the ones you need (typically 0 for luminance, 1 for chrominance).
  3. Inspect the file and count the number of 64-value blocks to identify which to remove.

Example fix

# before (5 tables of 64 values each in file.qtl)
cjpeg -qtables file.qtl image.bmp > out.jpg
# after (keep only 4 tables, remove the 5th block)
cjpeg -qtables trimmed.qtl image.bmp > out.jpg
Defensive patterns

Strategy: validation

Validate before calling

// Pre-validate table count: count 64-value blocks in the file
#include <stdio.h>
static int count_quant_tables(const char *filename) {
  FILE *fp = fopen(filename, "r");
  if (!fp) return -1;
  long val; int termchar, count = 0, vals = 0;
  while (read_text_integer(fp, &val, &termchar)) {
    vals++;
    if (vals % 64 == 0) count++;
  }
  fclose(fp);
  return count;
}

Prevention

When it happens

Trigger: Providing a quantization table file that contains 5 or more sets of 64 values. Each set of 64 integers counts as one table, and the tblno counter increments past NUM_QUANT_TBLS (typically 4).

Common situations: Concatenating multiple table files without removing extras; misunderstanding the table format and providing too many 64-value groups; generated table files that include more tables than the JPEG standard supports.

Related errors


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