[New-bugs-announce] [issue12051] Segfault in JSONEncoder subclasses with check_circular=False

Ezio Melotti report at bugs.python.org
Tue May 10 18:17:29 CEST 2011


New submission from Ezio Melotti <ezio.melotti at gmail.com>:

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.

----------
assignee: ezio.melotti
components: Extension Modules
files: issue12051.diff
keywords: needs review, patch
messages: 135716
nosy: ezio.melotti
priority: normal
severity: normal
stage: commit review
status: open
title: Segfault in JSONEncoder subclasses with check_circular=False
type: crash
versions: Python 2.7
Added file: http://bugs.python.org/file21955/issue12051.diff

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12051>
_______________________________________


More information about the New-bugs-announce mailing list