Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-134119: Fix crash from calling next() on exhausted template iterator#134120

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
JelleZijlstra merged 2 commits intopython:mainfromJelleZijlstra:templateiter-crash
May 17, 2025

Conversation

JelleZijlstra
Copy link
Member

@JelleZijlstraJelleZijlstra commentedMay 17, 2025
edited by bedevere-appbot
Loading

devdanzin, davepeck, srinivasreddy, and bswck reacted with heart emoji
@@ -23,6 +23,9 @@ templateiter_next(PyObject *op)
if (self->from_strings) {
item = PyIter_Next(self->stringsiter);
self->from_strings = 0;
if (item == NULL) {
return NULL;
}
if (PyUnicode_GET_LENGTH(item) == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Maybe it is worth to add condition here like

if (!item || PyUnicode_GET_LENGTH(item) == 0) {  Py_XSETREF(item, PyItem_Next(self->interpolationsiter));  self->from_strings = 1;}

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think that would potentially make an API call with an exception set, which is not allowed, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yeah, good point. Thanks!

Copy link
Contributor

@cfbolzcfbolz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Looks good!

@@ -23,6 +23,9 @@ templateiter_next(PyObject *op)
if (self->from_strings) {
item = PyIter_Next(self->stringsiter);
self->from_strings = 0;
if (item == NULL) {
return NULL;
}
if (PyUnicode_GET_LENGTH(item) == 0) {
Py_SETREF(item, PyIter_Next(self->interpolationsiter));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Should the result ofPyIter_Next(self->interpolationsiter) be checked forNULL too?

Copy link
Contributor

@davepeckdavepeckMay 17, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

That case just falls through to returningNULL safely, so it's probably fine as-is.

(The fall-through is intentional: since there is always one morestring thaninterpolation, the firstNULL returned by the iterator will always be here.)

devdanzin, lysnikolaou, and sergey-miryanov reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Py_SETREF is safe if it assigns to NULL, the behavior should be correct in that case.

Copy link
Member

@lysnikolaoulysnikolaou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Looks good to me as soon as@picnixz's feedback has been addressed.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@JelleZijlstraJelleZijlstra merged commitfc7f4c3 intopython:mainMay 17, 2025
39 checks passed
@miss-islington-app
Copy link

Thanks@JelleZijlstra for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestMay 17, 2025
…iterator (pythonGH-134120)(cherry picked from commitfc7f4c3)Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@bedevere-app
Copy link

GH-134153 is a backport of this pull request to the3.14 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.14bugs and security fixes labelMay 17, 2025
JelleZijlstra added a commit that referenced this pull requestMay 17, 2025
… iterator (GH-134120) (#134153)gh-134119: Fix crash from calling next() on exhausted template iterator (GH-134120)(cherry picked from commitfc7f4c3)Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@davepeckdavepeckdavepeck left review comments

@sergey-miryanovsergey-miryanovsergey-miryanov left review comments

@picnixzpicnixzpicnixz approved these changes

@lysnikolaoulysnikolaoulysnikolaou left review comments

@devdanzindevdanzindevdanzin left review comments

@cfbolzcfbolzcfbolz approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

8 participants
@JelleZijlstra@davepeck@sergey-miryanov@cfbolz@picnixz@lysnikolaou@devdanzin@hugovk

[8]ページ先頭

©2009-2025 Movatter.jp