diff --git a/src/_png.cpp b/src/_png.cpp index da8f696d7fcc..f40c009d3b1b 100644 --- a/src/_png.cpp +++ b/src/_png.cpp @@ -300,7 +300,11 @@ static PyObject *Py_write_png(PyObject *self, PyObject *args, PyObject *kwds) #ifdef PNG_TEXT_SUPPORTED // Save the metadata - if (metadata != NULL) { + if (metadata != NULL && metadata != Py_None) { + if (!PyDict_Check(metadata)) { + PyErr_SetString(PyExc_TypeError, "metadata must be a dict or None"); + goto exit; + } meta_size = PyDict_Size(metadata); text = new png_text[meta_size];