Skip to content

Move kernel size check into getlist() - #9987

Merged
hugovk merged 2 commits into
python-pillow:mainfrom
radarhere:kernel
Sep 14, 2026
Merged

hugovk merged 2 commits into
python-pillow:mainfrom
radarhere:kernel

Conversation

@radarhere

Copy link
Copy Markdown
Member

Within _prepare_lut_table(), _point() and _transform(), a size is passed to getlist()

table_data = getlist(table, &table_size, wrong_size, TYPE_FLOAT32);

which then checks it and raises a ValueError if it is incorrect.

Pillow/src/_imaging.c

Lines 447 to 450 in 0253ef0

if (length && wrong_length && n != *length) {
PyErr_SetString(PyExc_ValueError, wrong_length);
return NULL;
}

However, _filter() asks getlist() for the length and then checks it afterwards.

kerneldata = getlist(kernel, &kernelsize, NULL, TYPE_FLOAT32);

Pillow/src/_imaging.c

Lines 496 to 498 in 0253ef0

if (length) {
*length = n;
}

Pillow/src/_imaging.c

Lines 1174 to 1177 in 0253ef0

if (kernelsize != (Py_ssize_t)xsize * (Py_ssize_t)ysize) {
free(kerneldata);
return ImagingError_ValueError("bad kernel size");
}

It would be simpler to use the same strategy for all scenarios.

@hugovk
hugovk merged commit 27c2917 into python-pillow:main Sep 14, 2026
57 checks passed
@radarhere
radarhere deleted the kernel branch September 14, 2026 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants