New submission from Serhiy Storchaka:

It is possible to get a core dump by using uninitialized _json objects.

$ ./python -c "import _json; _json.make_scanner.__new__(_json.make_scanner)('', 
0)"
Segmentation fault (core dumped)
$ ./python -c "import _json; 
_json.make_encoder.__new__(_json.make_encoder)([0], 0)"
Segmentation fault (core dumped)

The cause is that make_scanner and make_encoder classes implement __new__ and 
__init__. The __new__ methods create uninitialized object, with NULLs pointers, 
the __init__ methods initialize them. Possible solutions are: 1) set fields to 
Py_None rather than NULL in __new__; 2) check every pointer for NULL before 
using; 3) just remove __init__ methods and make initialization in __new__ 
methods. Since the scanner and the encoder are not inheritable classes, the 
latter solution look the most preferable to me.

----------
components: Extension Modules
messages: 292846
nosy: bob.ippolito, ezio.melotti, rhettinger, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Core dump when use uninitialized _json objects
type: crash
versions: Python 2.7, Python 3.5, Python 3.6, Python 3.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue30243>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to