{"record":{"id":"4e39488425b24512","repo":"DrKLO/Telegram","slug":"too-many-components-in-one-scan-in-file-s","errorCode":null,"errorMessage":"Too many components in one scan in file %s\n","messagePattern":"Too many components in one scan in file (.+?)\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"TMessagesProj/jni/mozjpeg/rdswitch.c","lineNumber":212,"sourceCode":"\n  if ((fp = fopen(filename, \"r\")) == NULL) {\n    fprintf(stderr, \"Can't open scan definition file %s\\n\", filename);\n    return FALSE;\n  }\n  scanptr = scans;\n  scanno = 0;\n\n  while (read_scan_integer(fp, &val, &termchar)) {\n    if (scanno >= MAX_SCANS) {\n      fprintf(stderr, \"Too many scans defined in file %s\\n\", filename);\n      fclose(fp);\n      return FALSE;\n    }\n    scanptr->component_index[0] = (int) val;\n    ncomps = 1;\n    while (termchar == ' ') {\n      if (ncomps >= MAX_COMPS_IN_SCAN) {\n        fprintf(stderr, \"Too many components in one scan in file %s\\n\",\n                filename);\n        fclose(fp);\n        return FALSE;\n      }\n      if (! read_scan_integer(fp, &val, &termchar))\n        goto bogus;\n      scanptr->component_index[ncomps] = (int) val;\n      ncomps++;\n    }\n    scanptr->comps_in_scan = ncomps;\n    if (termchar == ':') {\n      if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ')\n        goto bogus;\n      scanptr->Ss = (int) val;\n      if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ')\n        goto bogus;\n      scanptr->Se = (int) val;\n      if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ')","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/mozjpeg/rdswitch.c#L194-L230","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","solutions":["Limit each scan entry to at most MAX_COMPS_IN_SCAN (typically 4) component indices.","Split the scan into multiple entries, each referencing fewer components.","Review the JPEG standard: standard JPEG images have at most 3-4 components (Y, Cb, Cr, or CMYK)."],"exampleFix":"# before: scan entry \"0 1 2 3 4: 0 0 0 0 0\" (5 components)\n# after: split into two scans\n# Scan 1: \"0 1 2: 0 0 0 0 0;\"\n# Scan 2: \"3: 0 0 0 0;\"","handlingStrategy":"validation","validationCode":"// Pre-validate: count component indices per scan entry\nstatic boolean validate_scan_components(const char *filename) {\n  FILE *fp = fopen(filename, \"r\");\n  if (!fp) return FALSE;\n  int c, comps = 0;\n  while ((c = fgetc(fp)) != EOF) {\n    if (c == ' ') comps++;\n    else if (c == ':') { if (comps > 4) { fclose(fp); return FALSE; } comps = 0; }\n    else if (c == ';') comps = 0;\n  }\n  fclose(fp);\n  return TRUE;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Limit each scan entry to at most 4 component indices (MAX_COMPS_IN_SCAN).","Standard JPEG images have at most 4 components (YCbCr + alpha, or CMYK).","Review scan scripts to ensure no entry references more components than the image has."],"tags":["validation","scan-definition","buffer-overflow-guard","mozjpeg"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}