From c5b343d389fce715383475415f5038d52f409e20 Mon Sep 17 00:00:00 2001 From: Nulano Date: Mon, 1 Jan 2024 00:48:13 +0100 Subject: [PATCH] check type given to ImageCms.core.profile_tobytes instead of crashing --- Tests/test_imagecms.py | 6 ++++++ src/_imagingcms.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Tests/test_imagecms.py b/Tests/test_imagecms.py index 0dde82bd748..ae9a361e943 100644 --- a/Tests/test_imagecms.py +++ b/Tests/test_imagecms.py @@ -489,6 +489,12 @@ def test_profile_typesafety(): 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, transform_in_place, preserved_channel): def create_test_image(): diff --git a/src/_imagingcms.c b/src/_imagingcms.c index 56d5d73f83c..2d6d22dd137 100644 --- a/src/_imagingcms.c +++ b/src/_imagingcms.c @@ -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; }