Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.13] gh-122527: Fix a crash on deallocation of PyStructSequence (GH-122577) #122625

Merged
merged 1 commit into from
Sep 2, 2024

Conversation

miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Aug 2, 2024

The PyStructSequence destructor would crash if it was deallocated after
its type's dictionary was cleared by the GC, because it couldn't compute
the "real size" of the instance. This could occur with relatively
straightforward code in the free-threaded build or with a reference
cycle involving the type in the default build, due to differing orders
in which tp_clear() was called.

Account for the non-sequence fields in tp_basicsize and use that,
along with Py_SIZE(), to compute the "real" size of a
PyStructSequence in the dealloc function. This avoids the accesses to
the type's dictionary during dealloc, which were unsafe.
(cherry picked from commit 4b63cd1)

Co-authored-by: Sam Gross [email protected]

…ythonGH-122577)

The `PyStructSequence` destructor would crash if it was deallocated after
its type's dictionary was cleared by the GC, because it couldn't compute
the "real size" of the instance. This could occur with relatively
straightforward code in the free-threaded build or with a reference
cycle involving the type in the default build, due to differing orders
in which `tp_clear()` was called.

Account for the non-sequence fields in `tp_basicsize` and use that,
along with `Py_SIZE()`, to compute the "real" size of a
`PyStructSequence` in the dealloc function. This avoids the accesses to
the type's dictionary during dealloc, which were unsafe.
(cherry picked from commit 4b63cd1)

Co-authored-by: Sam Gross <[email protected]>
@XuehaiPan
Copy link
Contributor

Out of curious, would this patch be included in Python 3.13.0rc2?

@Yhg1s Yhg1s merged commit 57ba3b0 into python:3.13 Sep 2, 2024
39 checks passed
@Yhg1s
Copy link
Member

Yhg1s commented Sep 2, 2024

Out of curious, would this patch be included in Python 3.13.0rc2?

Yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants