Skip to content

gh-139122: Fix crash when pickling a C UUID without is_safe - #160574

Open
tonghuaroot wants to merge 1 commit into
python:mainfrom
tonghuaroot:gh-139122-uuid-getstate-null-is-safe
Open

tonghuaroot wants to merge 1 commit into
python:mainfrom
tonghuaroot:gh-139122-uuid-getstate-null-is-safe

Conversation

@tonghuaroot

@tonghuaroot tonghuaroot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

The C UUID.__getstate__() passes self->is_safe to PyDict_SetItem() even when it is NULL, which is the case for every UUID created without is_safe (uuid4(), uuid7(), UUID(hex), UUID(int=...)). Pickling or copying such a UUID aborts on a debug build and segfaults on a release build:

import pickle, uuid
pickle.dumps(uuid.uuid4())

Omit the key in that case, as the pure Python __getstate__() does for SafeUUID.unknown. The C implementation is unreleased, so there is no NEWS entry.

UUID.__getstate__() passed a NULL is_safe to PyDict_SetItem() for every
UUID created without is_safe. Omit the key, as the Python version does
for SafeUUID.unknown.
@bedevere-app bedevere-app Bot added awaiting review type-feature A feature request or enhancement labels Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant