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
set_swap_bodies is unsafe #47027
Comments
set_swap_bodies() is used to cheaply create a frozenset from a set, Unfortunately, the lookup can invoke arbitrary code, which may examine The purpose seems to be allowing "someset in someotherset" to set_intersection_update uses set_swap_bodies for a different purpose and |
set_swap_bodies() is fine as it involves pure C with no possible Am lowering the priority because you really have to be trying to create |
The intended use is unsafe. contains, remove, and discard all use it Upon further inspection, intersection_update is fine. Only a temporary If someone can confirm that contains/remove/discard's usage is an |
I decided not to wait. Here's a patch. Several of set's unit tests covered the auto-conversion, so I've |
Rejecting this patch which simply disables a feature that some users I will look at it further. Right now, I'm inclined to simply document The set_swap_bodies() function itself is fine -- it behaves just like The issue is simply that the swap/search/swap dance allows the I'm am entertaining an alternative where contains/discard/remove would |
PEP-218 explicitly dropped auto-conversion as a feature. Why should |
If needed, I'll update the PEP to be more clear. The sets.py module |
Added documentation in r62873. Leaving the code as-is. |
Nevermind that the current implementation *is* broken, even if you |
Sorry, you don't like the search with autopromotion feature. It has |
So why doesn't set() in {} work? Why was PEP-351 rejected when it would |
Here's another approach to avoiding set_swap_bodies. The existing I even retain the current semantics of PySet_Discard and PySet_Contains, I do have some concern that calling PySet_Check on every call may be too set_swap_bodies has only one remaining caller, and their use case could |
Revised again. sets are only hashed after PyObject_Hash raises a TypeError. This also fixes a regression in test_subclass_with_custom_hash. Oddly, |
By replacing temporary immutability with temporary hashability, does Also, after a quick look at the patch, I'm not too keen on any |
There is no temporary hashability. The hash value is calculated, but set_contains_key only has two callers, one for each value of the set_swap_bodies has only one remaining caller, which uses a normal set, |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: