We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 17c19e1 commit ee59ca6Copy full SHA for ee59ca6
1 file changed
src/jsonb.c
@@ -879,15 +879,29 @@ jsonb_encode_internal_actual(struct JSONBuffer *buf, PyObject *obj)
879
/* the expected code path */
880
Py_ssize_t pos = 0;
881
PyObject *key, *value;
882
- while (PyDict_Next(obj, &pos, &key, &value))
+
883
+ /* take a copy of the dict to avoid mutation crashes possible
884
+ when doing encoding */
885
+ PyObject *copy = PyDict_Copy(obj);
886
+ if (!copy)
887
+ goto error;
888
889
+ while (PyDict_Next(copy, &pos, &key, &value))
890
{
891
size_t offset = buf->size;
892
893
if (jsonb_encode_object_key(buf, key))
894
+ {
895
+ Py_DECREF(copy);
896
goto error;
897
+ }
898
if (buf->size != offset && jsonb_encode_internal(buf, value))
899
900
901
902
903
}
904
905
906
else
907
0 commit comments