Skip to content

Commit f26774c

Browse files
authored
Merge pull request #13923 from QuLogic/png-metadata-crash
Correctly handle invalid PNG metadata.
2 parents b9b9845 + 511df0f commit f26774c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/_png.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,11 @@ static PyObject *Py_write_png(PyObject *self, PyObject *args, PyObject *kwds)
300300

301301
#ifdef PNG_TEXT_SUPPORTED
302302
// Save the metadata
303-
if (metadata != NULL) {
303+
if (metadata != NULL && metadata != Py_None) {
304+
if (!PyDict_Check(metadata)) {
305+
PyErr_SetString(PyExc_TypeError, "metadata must be a dict or None");
306+
goto exit;
307+
}
304308
meta_size = PyDict_Size(metadata);
305309
text = new png_text[meta_size];
306310

0 commit comments

Comments
 (0)