Skip to content

gh-150001: fix escalation to SystemError during parsing - #150067

Open
sandugood wants to merge 11 commits into
python:mainfrom
sandugood:gh-150001
Open

sandugood wants to merge 11 commits into
python:mainfrom
sandugood:gh-150001

Conversation

@sandugood

@sandugood sandugood commented May 19, 2026 •

Copy link
Copy Markdown

Added a regression test as well (with the string generated by fuzzer in the issue).

@bedevere-app

bedevere-app Bot commented May 19, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@python-cla-bot

python-cla-bot Bot commented May 19, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

Comment thread Lib/test/test_compile.py Outdated
@bedevere-app

bedevere-app Bot commented May 19, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@sandugood

Copy link
Copy Markdown
Author

I think that this fix doesn't require a NEWS entry. But I am opened to suggestions

@pablogsal

Copy link
Copy Markdown
Member

We need a news entry can you add one please?

@sandugood

Copy link
Copy Markdown
Author

Yes, sure. Thanks for the review

@sandugood

Copy link
Copy Markdown
Author

Seems that the CI error is not related to the PR itself.

@JelleZijlstra

Copy link
Copy Markdown
Member

I retried it

@sandugood

Copy link
Copy Markdown
Author

I retried it

Looks like it is a github issue? The run itself doesnt get to the building stage

@sandugood

Copy link
Copy Markdown
Author

Thank you for the CI rerun. All of the tests have passed

@sandugood

Copy link
Copy Markdown
Author

Could you, please, review this PR if you have time @lysnikolaou?
Thank you in advance

Comment thread Lib/test/test_compile.py Outdated
@sandugood

Copy link
Copy Markdown
Author

Sorry for a late response @StanFromIreland
Thank you for your review

@stestagg

stestagg commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Worth considering if this would be neater? If we assume that parse failure paths always return NULL, then you can

diff --git a/Tools/peg_generator/pegen/c_generator.py b/Tools/peg_generator/pegen/c_generator.py
index d9236dfb22835bd..bb0cc34c68a75e9 100644
--- a/Tools/peg_generator/pegen/c_generator.py
+++ b/Tools/peg_generator/pegen/c_generator.py
@@ -658,10 +658,12 @@ def _handle_loop_rule_body(self, node: Rule, rhs: Rhs) -> None:
             )
             if is_repeat1:
                 self.print("if (_n == 0 || p->error_indicator) {")
-                with self.indent():
-                    self.print("PyMem_Free(_children);")
-                    self.add_return("NULL")
-                self.print("}")
+            else:
+                self.print("if (p->error_indicator) {")
+            with self.indent():
+                self.print("PyMem_Free(_children);")
+                self.add_return("NULL")
+            self.print("}")
             self.print("asdl_seq *_seq = (asdl_seq*)_Py_asdl_generic_seq_new(_n, p->arena);")
             self.out_of_memory_return("!_seq", cleanup_code="PyMem_Free(_children);")
             self.print("for (Py_ssize_t i = 0; i < _n; i++) asdl_seq_SET_UNTYPED(_seq, i, _children[i]);")

This way we have one check shared between loop0 and loop1 without duplicating it on the loop1?

BTW: this code is new to me, so I probably made some assumptions here!

@sandugood

Copy link
Copy Markdown
Author

I think we can merge this ver and then reiterate with a follow up?
Wdyt @stestagg?

@StanFromIreland

Copy link
Copy Markdown
Member

Can you please fix the conflicts?

@sandugood

Copy link
Copy Markdown
Author

Can you please fix the conflicts?

Sure, working on it now

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

Labels

awaiting review needs backport to 3.13 only security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants