DrKLO/Telegram · error
JPEG quantization tables are numbered 0..%d
Error message
JPEG quantization tables are numbered 0..%d
What it means
The set_quant_slots function processes the -qslots argument, which maps color components to quantization table indices. JPEG supports NUM_QUANT_TBLS tables (typically 4, numbered 0-3). If any table index in the argument is negative or >= NUM_QUANT_TBLS, the function prints this error and returns FALSE. This validates the component-to-table mapping before compression begins.
Source
Thrown at TMessagesProj/jni/mozjpeg/rdswitch.c:590
set_quant_slots (j_compress_ptr cinfo, char *arg)
/* Process a quantization-table-selectors parameter string, of the form
* N[,N,...]
* If there are more components than parameters, the last value is replicated.
*/
{
int val = 0; /* default table # */
int ci;
char ch;
for (ci = 0; ci < MAX_COMPONENTS; ci++) {
if (*arg) {
ch = ','; /* if not set by sscanf, will be ',' */
if (sscanf(arg, "%d%c", &val, &ch) < 1)
return FALSE;
if (ch != ',') /* syntax check */
return FALSE;
if (val < 0 || val >= NUM_QUANT_TBLS) {
fprintf(stderr, "JPEG quantization tables are numbered 0..%d\n",
NUM_QUANT_TBLS-1);
return FALSE;
}
cinfo->comp_info[ci].quant_tbl_no = val;
while (*arg && *arg++ != ','); /* advance to next segment of arg
string */
} else {
/* reached end of parameter, set remaining components to last table */
cinfo->comp_info[ci].quant_tbl_no = val;
}
}
return TRUE;
}
GLOBAL(boolean)
set_sample_factors (j_compress_ptr cinfo, char *arg)
/* Process a sample-factors parameter string, of the formView on GitHub (pinned to 45ab8f4308)
Solutions
- Use only table indices 0 through NUM_QUANT_TBLS-1 (typically 0-3).
- Remember indices are 0-based: 0=luminance, 1=chrominance is the standard mapping.
- For a standard YCbCr image, -qslots 0,1,1 maps Y to table 0 and Cb/Cr to table 1.
Example fix
# before cjpeg -qslots 0,5 image.bmp > out.jpg # after cjpeg -qslots 0,1,1 image.bmp > out.jpg
Defensive patterns
Strategy: validation
Validate before calling
// Pre-validate qslots argument before calling set_quant_slots
static boolean validate_qslots_arg(const char *arg) {
const char *p = arg;
while (*p) {
int val;
char ch = ',';
if (sscanf(p, "%d%c", &val, &ch) < 1) return FALSE;
if (val < 0 || val >= NUM_QUANT_TBLS) return FALSE;
while (*p && *p++ != ',') ;
}
return TRUE;
} Prevention
- Use only table indices 0 to NUM_QUANT_TBLS-1 (typically 0-3).
- Remember indices are 0-based.
- For standard YCbCr: -qslots 0,1,1 is the default luminance/chrominance mapping.
- Validate each comma-separated value is in range before passing.
When it happens
Trigger: Passing -qslots with a value outside 0..NUM_QUANT_TBLS-1 (typically 0..3). For example 'cjpeg -qslots 4 image.bmp' or '-qslots 0,5' where 5 exceeds the table limit. The sscanf parses the integer and the bounds check fires.
Common situations: Misunderstanding the number of available quantization tables; passing a 1-based index instead of 0-based; using a table number that was defined in a different build or library version; typos in the argument string.
Related errors
- Too many tables in file %s
- Invalid table data in file %s
- Non-numeric data in file %s
- JPEG sampling factors must be 1..4
- %s: skip region exceeds image height %d\n
AI-assisted analysis of DrKLO/Telegram@45ab8f4308 (2026-08-14).
Data as JSON: /api/errors/abf53159398fa0fc.
Report an issue: GitHub.