Skip to content

Conversation

@skirpichev
Copy link
Contributor

@skirpichev skirpichev commented Jan 3, 2026

@skirpichev skirpichev force-pushed the fix-uaf-s_pack_internal/143379 branch from 0bfe0a3 to a1c2603 Compare January 3, 2026 07:36
@skirpichev skirpichev requested a review from vstinner January 3, 2026 07:41
@skirpichev
Copy link
Contributor Author

Alternative approach: use some flag in PyStructObject struct to forbid mutation during pack().

@vstinner
Copy link
Member

vstinner commented Jan 5, 2026

Alternative approach: use some flag in PyStructObject struct to forbid mutation during pack().

Would it be possible to always disallow mutation? Raise an exception if __init__() is called twice.

@skirpichev
Copy link
Contributor Author

Why there is __init__() method at all? The Struct expected to be an immutable type.

Maybe all logic in Struct___init__ (tp_init) should be moved to s_new (tp_new)? I think this will fix issue. Looking in the history, the custom __init__() was re-introduced back in #112358.

Here is the plan:

  1. create a flag to temporary forbid mutation
  2. deprecate Struct.__new__() calls without one required argument
  3. eventually drop Struct.__init__() together with a flag

CC @serhiy-storchaka

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants