check type given to ImageCms.core.profile_tobytes instead of crashing

This commit is contained in:
Nulano 2024-01-01 00:48:13 +01:00
parent e7eea5ea30
commit 24ed5db2d1
2 changed files with 7 additions and 1 deletions

View File

@ -506,6 +506,12 @@ def test_profile_typesafety() -> None:
with pytest.raises(TypeError, match="Invalid type for Profile"):
ImageCms.ImageCmsProfile(1).tobytes()
# also check core function
with pytest.raises(TypeError):
ImageCms.core.profile_tobytes(0)
with pytest.raises(TypeError):
ImageCms.core.profile_tobytes(1)
def assert_aux_channel_preserved(
mode: str, transform_in_place: bool, preserved_channel: str

View File

@ -143,7 +143,7 @@ cms_profile_tobytes(PyObject *self, PyObject *args) {
cmsHPROFILE *profile;
PyObject *ret;
if (!PyArg_ParseTuple(args, "O", &CmsProfile)) {
if (!PyArg_ParseTuple(args, "O!", &CmsProfile_Type, &CmsProfile)) {
return NULL;
}