gh-135241: Changed the opcode of _pickle module to look for 00 and 01 specifically#135242
Merged
serhiy-storchaka merged 8 commits intopython:mainfrom Aug 14, 2025
Merged
Conversation
The python pickle module looks for "00" and "01" but _pickle only looked for 2 characters that parsed to 0 or 1, meaning some payloads like "+0" or " 0" would lead to different results in different implementations
Lib/test/test_pickle.py
Outdated
| # when getting booleans from the INT opcode. Doing a str comparison | ||
| # to bypass truthy/falsy comparisons. These payloads should return | ||
| # 0, not False. | ||
| out1 = self.loads(b'I+0\n.') |
Contributor
Author
There was a problem hiding this comment.
The INT opcode only looks specifically for the b'I01' and b'I00' values to convert to True/False. Because of #126992, both implementations specifically use base 10 so b'I001' will push 1 to the stack for both, so that shouldn't be relevant here I don't think.
skirpichev
approved these changes
Aug 13, 2025
Member
skirpichev
left a comment
There was a problem hiding this comment.
LGTM, small formatting nitpick
Misc/NEWS.d/next/Library/2025-06-08-01-10-34.gh-issue-135241.5j18IW.rst
Outdated
Show resolved
Hide resolved
…j18IW.rst Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Contributor
Author
|
Merged both suggested changes - thanks! |
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka
approved these changes
Aug 14, 2025
Agent-Hellboy
pushed a commit
to Agent-Hellboy/cpython
that referenced
this pull request
Aug 19, 2025
pythonGH-135242) The Python pickle module looks for "00" and "01" but _pickle only looked for 2 characters that parsed to 0 or 1, meaning some payloads like "+0" or " 0" would lead to different results in different implementations.
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.
The python pickle module looks for "00" and "01" but _pickle only looked for 2 characters that parsed to 0 or 1, meaning some payloads like "+0" or " 0" would lead to different results in different implementations. See more details in the linked issue.
This solution simply checks for the hard-coded chars ensuring no edge cases go by.
INTopcode boolean conversion discrepancy #135241