Issue 12051: Segfaults in _json while encoding objects (original) (raw)
Subclasses of JSONEncoder that use check_circular=False can segfault json:
import json class EndlessJSONEncoder(json.JSONEncoder): ... def default(self, o): ... return [o] ... EndlessJSONEncoder(check_circular=False).encode(5j) Segmentation fault
The attached patch fixes it raising a "RuntimeError: maximum recursion depth exceeded".
There might be other ways to get a segfault, because there are other recursive calls involving more functions (i.e. a calls b, and b calls a) that are not covered by the patch.