[New-bugs-announce] [issue31779] assertion failures and a crash when using an uninitialized struct.Struct object

Oren Milman report at bugs.python.org
Fri Oct 13 06:54:20 EDT 2017


New submission from Oren Milman <orenmn at gmail.com>:

The following code causes an assertion failure:
    import _struct
    struct_obj = _struct.Struct.__new__(_struct.Struct)
    struct_obj.iter_unpack(b'foo')

This is because Struct_iter_unpack() (in Modules/_struct.c) assumes that
Struct.__init__() was called, and so it does `assert(self->s_codes != NULL);`.

The same happens in (almost) every method of Struct, and in s_get_format(), so
in all them, too, we would get an assertion failure in case of an uninitialized
Struct object.
The exception is __sizeof__(), which doesn't have an `assert`, and simply
crashes while trying to iterate over `self->s_codes`.


I would open a PR to fix this soon.

----------
components: Extension Modules
messages: 304328
nosy: Oren Milman
priority: normal
severity: normal
status: open
title: assertion failures and a crash when using an uninitialized struct.Struct object
type: crash
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue31779>
_______________________________________


More information about the New-bugs-announce mailing list