This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: assertion failures and a crash when using an uninitialized struct.Struct object
Type: crash Stage: patch review
Components: Extension Modules Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Oren Milman, berker.peksag, iritkatriel, izbyshev, mark.dickinson, meador.inge, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2017-10-13 10:54 by Oren Milman, last changed 2022-04-11 14:58 by admin.

Pull Requests
URL Status Linked Edit
PR 3984 open Oren Milman, 2017-10-13 14:14
Messages (3)
msg304328 - (view) Author: Oren Milman (Oren Milman) * Date: 2017-10-13 10:54
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.
msg325462 - (view) Author: Alexey Izbyshev (izbyshev) * (Python triager) Date: 2018-09-15 22:53
What are the drawbacks of moving all code from __init__ to __new__, at least in master branch (3.8)? IMO it's much more robust than playing whack-a-mole both with ref/memleaks caused by repeated calls to __init__ and absence of initialization checks in all methods.
msg404285 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-10-19 10:22
Reproduced on 3.11.
History
Date User Action Args
2022-04-11 14:58:53adminsetgithub: 75960
2021-10-19 10:22:17iritkatrielsetnosy: + iritkatriel

messages: + msg404285
versions: + Python 3.9, Python 3.10, Python 3.11, - Python 2.7, Python 3.7, Python 3.8
2019-05-20 22:29:12cheryl.sabellasetversions: - Python 3.6
2018-09-15 22:53:38izbyshevsetnosy: + izbyshev, meador.inge, berker.peksag, serhiy.storchaka, mark.dickinson

messages: + msg325462
versions: + Python 2.7, Python 3.6, Python 3.8
2017-10-13 14:14:21Oren Milmansetkeywords: + patch
stage: patch review
pull_requests: + pull_request3960
2017-10-13 10:54:20Oren Milmancreate