Skip to content

gh-133516: Raise ValueError when constants True, False or None are used as an identifier after NFKC normalization #133523

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

Merged
merged 5 commits into from
May 7, 2025

Conversation

TERESH1
Copy link
Contributor

@TERESH1 TERESH1 commented May 6, 2025

@python-cla-bot
Copy link

python-cla-bot bot commented May 6, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

TERESH1 and others added 2 commits May 6, 2025 19:25
Add dot to end

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Copy link
Member

@pablogsal pablogsal left a comment

Choose a reason for hiding this comment

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

LGTM

@pablogsal pablogsal added needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes and removed needs backport to 3.12 only security fixes labels May 6, 2025
Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

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

Formatting silliness

@ZeroIntensity
Copy link
Member

Actually, wait a minute--@pablogsal, could you reproduce this on main or 3.13? I can't with either the test case or the reproducer provided in the issue. I don't see how this could possibly be platform-dependent.

@pablogsal
Copy link
Member

Actually, wait a minute--@pablogsal, could you reproduce this on main or 3.13? I can't with either the test case or the reproducer provided in the issue. I don't see how this could possibly be platform-dependent.

Humm good point. In macOS I am seeing this:

Python 3.14.0a7+ (heads/main-dirty:3dfed230928, May  6 2025, 16:15:52) [Clang 17.0.0 (clang-1700.0.13.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> compile(source=b'Fal\xc5\xbfe', filename="<test>", mode="exec")
Traceback (most recent call last):
  File "<python-input-0>", line 1, in <module>
    compile(source=b'Fal\xc5\xbfe', filename="<test>", mode="exec")
    ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: identifier field can't represent 'False' constant

@pablogsal
Copy link
Member

Is hitting this assert:

assert(!_PyUnicode_EqualToASCIIString(name, "None") &&

maybe we don't have asserts compiled in? But debug mode should not optimize them away....

@TERESH1
Copy link
Contributor Author

TERESH1 commented May 7, 2025

Actually, wait a minute--@pablogsal, could you reproduce this on main or 3.13? I can't with either the test case or the reproducer provided in the issue. I don't see how this could possibly be platform-dependent.

Humm good point. In macOS I am seeing this:

Python 3.14.0a7+ (heads/main-dirty:3dfed230928, May  6 2025, 16:15:52) [Clang 17.0.0 (clang-1700.0.13.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> compile(source=b'Fal\xc5\xbfe', filename="<test>", mode="exec")
Traceback (most recent call last):
  File "<python-input-0>", line 1, in <module>
    compile(source=b'Fal\xc5\xbfe', filename="<test>", mode="exec")
    ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: identifier field can't represent 'False' constant

Using Py_DEBUG, _PyAST_Validate is called after parsing AST

cpython/Parser/pegen.c

Lines 976 to 986 in 3dfed23

// test_peg_generator defines _Py_TEST_PEGEN to not call PyAST_Validate()
#if defined(Py_DEBUG) && !defined(_Py_TEST_PEGEN)
if (p->start_rule == Py_single_input ||
p->start_rule == Py_file_input ||
p->start_rule == Py_eval_input)
{
if (!_PyAST_Validate(res)) {
return NULL;
}
}
#endif

But if only asserts are enabled, then there is no AST validation

Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

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

LGTM as well now

@pablogsal pablogsal merged commit d9b0b07 into python:main May 7, 2025
39 checks passed
@miss-islington-app
Copy link

Thanks @TERESH1 for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Sorry, @TERESH1 and @pablogsal, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker d9b0b07098ec4bdb47151948c77bcbbf3e796a5d 3.13

@pablogsal pablogsal added the needs backport to 3.14 bugs and security fixes label May 7, 2025
@miss-islington-app
Copy link

Thanks @TERESH1 for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@bedevere-app
Copy link

bedevere-app bot commented May 7, 2025

GH-133596 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label May 7, 2025
@pablogsal
Copy link
Member

Sorry, @TERESH1 and @pablogsal, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker d9b0b07098ec4bdb47151948c77bcbbf3e796a5d 3.13

@TERESH1 can you do the backpory following this instruction?

@bedevere-app
Copy link

bedevere-app bot commented May 7, 2025

GH-133615 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label May 7, 2025
pablogsal pushed a commit that referenced this pull request May 7, 2025
…r `None` are used as an identifier after NFKC normalization (GH-133523) (#133596)
TERESH1 added a commit to TERESH1/cpython that referenced this pull request May 8, 2025
…lse` or `None` are used as an identifier after NFKC normalization (pythonGH-133523)

(cherry picked from commit d9b0b07)
TERESH1 added a commit to TERESH1/cpython that referenced this pull request May 8, 2025
…lse` or `None` are used as an identifier after NFKC normalization (pythonGH-133523)

(cherry picked from commit d9b0b07)
pablogsal pushed a commit that referenced this pull request May 8, 2025
…r `None` are used as an identifier after NFKC normalization (GH-133523) (#133615)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants