Skip to content

Move kernel size check into getlist() - #9987

Open
radarhere wants to merge 2 commits into
python-pillow:mainfrom
radarhere:kernel
Open

Move kernel size check into getlist()#9987
radarhere wants to merge 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.

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.

1 participant