Skip to content
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

gh-125660: Python implementation of json.loads() accepts invalid unicode escapes #125683

Merged
merged 7 commits into from
Oct 18, 2024

Conversation

nineteendo
Copy link
Contributor

@nineteendo nineteendo commented Oct 18, 2024

This condition in json.decoder is insufficient:

if len(esc) == 4 and esc[1] not in 'xX':

>>> import sys
>>> sys.modules["_json"] = None
>>> import json
>>> json.loads(r'["\u 000", "\u-000", "\u+000", "\u0_00"]')
['\x00', '\x00', '\x00', '\x00']

@nineteendo nineteendo marked this pull request as ready for review October 18, 2024 09:10
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.

For other reviewers, see also: #125687

I think this is fine, but per @taleinat, this shouldn't get backported--it's technically a very minor breaking change.

@taleinat
Copy link
Contributor

taleinat commented Oct 18, 2024

I think this is fine, but per @taleinat, this shouldn't get backported--it's technically a very minor breaking change.

After further consideration, I do consider this to be a clear bug fix, which should be backported to versions in "bugfix" status (i.e. 3.12).

@ZeroIntensity
Copy link
Member

Are you sure? I'm not certain what policy PyPy, IronPython, Jython, etc. have for changes that we backport, but point of pure-Python modules was almost exclusively for other Python implementations--I don't want to accidentally cause any surprises.

@taleinat
Copy link
Contributor

taleinat commented Oct 18, 2024

Are you sure?

No, I am not sure, I've been away from Python development for several years. It would be good to get another core dev's perspective.

@taleinat
Copy link
Contributor

Upon further consideration, yes, the chance of breaking something with a backport is large relative to the likely pain caused by the current, buggy, state. Let's avoid backporting.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

LGTM. 👍

@serhiy-storchaka
Copy link
Member

This is clearly a bug. json.loads() can be a part of validation. If it accepts an invalid JSON, it can fail later, in other program with more strict JSON parser. I do not think that anybody depends on such buggy behavior.

@serhiy-storchaka serhiy-storchaka merged commit df75136 into python:main Oct 18, 2024
40 checks passed
@miss-islington-app
Copy link

Thanks @nineteendo for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 18, 2024
…tion of JSON decoder (pythonGH-125683)

(cherry picked from commit df75136)

Co-authored-by: Nice Zombies <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 18, 2024
…tion of JSON decoder (pythonGH-125683)

(cherry picked from commit df75136)

Co-authored-by: Nice Zombies <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Oct 18, 2024

GH-125694 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 Oct 18, 2024
@bedevere-app
Copy link

bedevere-app bot commented Oct 18, 2024

GH-125695 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 bug and security fixes label Oct 18, 2024
@nineteendo nineteendo deleted the patch-1 branch October 18, 2024 12:30
serhiy-storchaka pushed a commit that referenced this pull request Oct 21, 2024
…ation of JSON decoder (GH-125683) (GH-125694)

(cherry picked from commit df75136)

Co-authored-by: Nice Zombies <[email protected]>
serhiy-storchaka pushed a commit that referenced this pull request Oct 21, 2024
…ation of JSON decoder (GH-125683) (GH-125695)

(cherry picked from commit df75136)

Co-authored-by: Nice Zombies <[email protected]>
ebonnal pushed a commit to ebonnal/cpython that referenced this pull request Jan 12, 2025
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