DrKLO/Telegram · error

Too many components in one scan in file %s

Error message

Too many components in one scan in file %s

What it means

Each scan entry in a progressive JPEG can reference at most MAX_COMPS_IN_SCAN components (typically 4). If a scan entry lists more component indices than this limit, the function reports the error, closes the file, and returns FALSE. This prevents writing beyond the component_index array bounds.

Source

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

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

  while (read_scan_integer(fp, &val, &termchar)) {
    if (scanno >= MAX_SCANS) {
      fprintf(stderr, "Too many scans defined in file %s\n", filename);
      fclose(fp);
      return FALSE;
    }
    scanptr->component_index[0] = (int) val;
    ncomps = 1;
    while (termchar == ' ') {
      if (ncomps >= MAX_COMPS_IN_SCAN) {
        fprintf(stderr, "Too many components in one scan in file %s\n",
                filename);
        fclose(fp);
        return FALSE;
      }
      if (! read_scan_integer(fp, &val, &termchar))
        goto bogus;
      scanptr->component_index[ncomps] = (int) val;
      ncomps++;
    }
    scanptr->comps_in_scan = ncomps;
    if (termchar == ':') {
      if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ')
        goto bogus;
      scanptr->Ss = (int) val;
      if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ')
        goto bogus;
      scanptr->Se = (int) val;
      if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ')

View on GitHub (pinned to 45ab8f4308)

Solutions

  1. Limit each scan entry to at most MAX_COMPS_IN_SCAN (typically 4) component indices.
  2. Split the scan into multiple entries, each referencing fewer components.
  3. Review the JPEG standard: standard JPEG images have at most 3-4 components (Y, Cb, Cr, or CMYK).

Example fix

# before: scan entry "0 1 2 3 4: 0 0 0 0 0" (5 components)
# after: split into two scans
# Scan 1: "0 1 2: 0 0 0 0 0;"
# Scan 2: "3: 0 0 0 0;"
Defensive patterns

Strategy: validation

Validate before calling

// Pre-validate: count component indices per scan entry
static boolean validate_scan_components(const char *filename) {
  FILE *fp = fopen(filename, "r");
  if (!fp) return FALSE;
  int c, comps = 0;
  while ((c = fgetc(fp)) != EOF) {
    if (c == ' ') comps++;
    else if (c == ':') { if (comps > 4) { fclose(fp); return FALSE; } comps = 0; }
    else if (c == ';') comps = 0;
  }
  fclose(fp);
  return TRUE;
}

Prevention

When it happens

Trigger: A scan definition entry with more than MAX_COMPS_IN_SCAN component index values separated by spaces before the colon. For example, '0 1 2 3 4:' would exceed the limit if MAX_COMPS_IN_SCAN is 4.

Common situations: Misunderstanding the scan script format and listing too many components per scan; typos that add extra numbers; scripts designed for images with more than 4 color components (unusual for standard JPEG).

Related errors


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