{"record":{"id":"fc13efcba68e0b16","repo":"DrKLO/Telegram","slug":"invalid-table-data-in-file-s","errorCode":null,"errorMessage":"Invalid table data in file %s\n","messagePattern":"Invalid table data in file (.+?)\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"TMessagesProj/jni/mozjpeg/rdswitch.c","lineNumber":112,"sourceCode":"  long val;\n  unsigned int table[DCTSIZE2];\n\n  if ((fp = fopen(filename, \"r\")) == NULL) {\n    fprintf(stderr, \"Can't open table file %s\\n\", filename);\n    return FALSE;\n  }\n  tblno = 0;\n\n  while (read_text_integer(fp, &val, &termchar)) { /* read 1st element of table */\n    if (tblno >= NUM_QUANT_TBLS) {\n      fprintf(stderr, \"Too many tables in file %s\\n\", filename);\n      fclose(fp);\n      return FALSE;\n    }\n    table[0] = (unsigned int) val;\n    for (i = 1; i < DCTSIZE2; i++) {\n      if (! read_text_integer(fp, &val, &termchar)) {\n        fprintf(stderr, \"Invalid table data in file %s\\n\", filename);\n        fclose(fp);\n        return FALSE;\n      }\n      table[i] = (unsigned int) val;\n    }\n#if JPEG_LIB_VERSION >= 70\n    jpeg_add_quant_table(cinfo, tblno, table, cinfo->q_scale_factor[tblno],\n                         force_baseline);\n#else\n    jpeg_add_quant_table(cinfo, tblno, table, q_scale_factor[tblno],\n                         force_baseline);\n#endif\n    tblno++;\n  }\n\n  if (termchar != EOF) {\n    fprintf(stderr, \"Non-numeric data in file %s\\n\", filename);\n    fclose(fp);","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/mozjpeg/rdswitch.c#L94-L130","documentation":"While reading a quantization table, read_quant_tables expects exactly 64 integer values per table. After reading the first value successfully, if any subsequent read_text_integer call fails (returns 0), it means the file ended prematurely or contains non-numeric data mid-table. The function reports invalid table data, closes the file, and returns FALSE.","triggerScenarios":"A quantization table file where a table has fewer than 64 values; a non-numeric token appears within a 64-value table block; the file is truncated in the middle of a table definition.","commonSituations":"Hand-edited table files with missing values; files generated by a script with an off-by-one error in the loop; copy-paste errors that dropped values; encoding issues (BOM, non-ASCII digits).","solutions":["Ensure each table contains exactly 64 whitespace-separated decimal integers.","Validate the file format programmatically: count tokens per table block before passing it to cjpeg.","Regenerate the table file using a script that guarantees 64 values per table."],"exampleFix":"# before (table file with 63 values in one block)\n# after (ensure exactly 64 values per table block)\npython3 -c \"print(' '.join(['%d' % (i+1) for i in range(64)]))\" > table.qtl","handlingStrategy":"validation","validationCode":"// Pre-validate: ensure each table block has exactly 64 integers\n#include <stdio.h>\nstatic boolean validate_quant_file(const char *filename) {\n  FILE *fp = fopen(filename, \"r\");\n  if (!fp) return FALSE;\n  long val; int termchar, vals = 0;\n  while (read_text_integer(fp, &val, &termchar)) {\n    vals++;\n  }\n  fclose(fp);\n  return (vals % DCTSIZE2 == 0);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Generate quantization table files programmatically to guarantee 64 values per table.","Count tokens per table block using awk or a script before passing to cjpeg.","Avoid hand-editing table files; use templates and sed for controlled modifications."],"tags":["validation","quantization","malformed-data","mozjpeg"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}