From c3d5e429acaf1018ea83ebb442b755d21f0986ae Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 26 Jun 2025 19:10:13 +1000 Subject: [PATCH] Fix crash assigning non UTF8 path to imbuf.filepath --- source/blender/python/generic/imbuf_py_api.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/blender/python/generic/imbuf_py_api.cc b/source/blender/python/generic/imbuf_py_api.cc index 2422021d5b2..d1be5c041d1 100644 --- a/source/blender/python/generic/imbuf_py_api.cc +++ b/source/blender/python/generic/imbuf_py_api.cc @@ -322,13 +322,16 @@ static int py_imbuf_filepath_set(Py_ImBuf *self, PyObject *value, void * /*closu ImBuf *ibuf = self->ibuf; const Py_ssize_t value_str_len_max = sizeof(ibuf->filepath); + PyObject *value_coerce = nullptr; Py_ssize_t value_str_len; - const char *value_str = PyUnicode_AsUTF8AndSize(value, &value_str_len); + const char *value_str = PyC_UnicodeAsBytesAndSize(value, &value_str_len, &value_coerce); if (value_str_len >= value_str_len_max) { PyErr_Format(PyExc_TypeError, "filepath length over %zd", value_str_len_max - 1); + Py_XDECREF(value_coerce); return -1; } memcpy(ibuf->filepath, value_str, value_str_len + 1); + Py_XDECREF(value_coerce); return 0; }