Forbid direct instantiation of iterator types#1377
Open
devdanzin wants to merge 4 commits into
Open
Conversation
type(iter(md.keys())).__new__(t) built an uninitialised iterator whose md pointer was NULL; calling next() on it dereferenced NULL and segfaulted. The view types were given a forbidden tp_new in aio-libs#1163 for the same reason (aio-libs#1161); the iterator types share the hole. Add the same forbidden tp_new to the items/keys/values iterator specs. Adds a C-extension regression test mirroring the view one.
for more information, see https://pre-commit.ci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What do these changes do?
type(iter(md.keys())).__new__(t)built an uninitialised iterator whose internalmdpointer was NULL;calling
next()on it dereferenced NULL and segfaulted. The view types were given a forbiddentp_newfor exactly this reason in #1163; the iterator types share the hole. This adds the same forbidden
tp_newto the items/keys/values iterator specs. This is a C-extension-only concern (the pure-Pythoniterators are ordinary Python objects); no pure-Python change is needed.
Are there changes in behavior for the user?
Yes: directly constructing an internal iterator type now raises
TypeError: cannot create '..._keysiter' instances directlyinstead of crashing. Normal iteration isunaffected.
Is it a substantial burden for the maintainers to support this?
No. It mirrors the existing view-type fix (#1163).
Related issue number
Direct analog of #1163 (view types); same crash class as #1161. Surfaced by the analysis report #1306.
Checklist
test_iter_direct_instantiation_segfault)CONTRIBUTORS.txtin this repoCHANGES/folder