gh-135321: Changing data type of size variable for BINSTRING in _pickle#135322
Merged
serhiy-storchaka merged 6 commits intopython:mainfrom Jun 11, 2025
Merged
Conversation
…opcode `BINSTRING` to `int` from `Py_ssize_t`
size variable for C implementation of pickle …size variable for BINSTRING in _pickle
Member
serhiy-storchaka
left a comment
There was a problem hiding this comment.
The bug was introduced in bpo-17810/gh-62010. The code should use calc_binsize() instead of calc_binsize().
And it is worth to add a test:
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py
index 9d6ae3e4d00..2a85e31078c 100644
--- a/Lib/test/pickletester.py
+++ b/Lib/test/pickletester.py
@@ -1100,6 +1100,11 @@ def test_large_32b_binunicode8(self):
self.check_unpickling_error((pickle.UnpicklingError, OverflowError),
dumped)
+ def test_large_binstring(self):
+ errmsg = 'UnpicklingError: BINSTRING pickle has negative byte count'
+ with self.assertRaisesRegex(pickle.UnpicklingError, errmsg):
+ self.loads(b'T\0\0\0\x80')
+
def test_get(self):
pickled = b'((lp100000\ng100000\nt.'
unpickled = self.loads(pickled)
Misc/NEWS.d/next/Library/2025-06-10-00-42-30.gh-issue-135321.UHh9jT.rst
Outdated
Show resolved
Hide resolved
Fix size Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Contributor
Author
|
I made all the requested changes - thank you! |
|
Thanks @Legoclones for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this pull request
Jun 11, 2025
…ent > 0x7fffffff in pickle (pythonGH-135322) (cherry picked from commit 2b8b477) Co-authored-by: Justin Applegate <70449145+Legoclones@users.noreply.github.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
|
GH-135382 is a backport of this pull request to the 3.14 branch. |
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this pull request
Jun 11, 2025
…ent > 0x7fffffff in pickle (pythonGH-135322) (cherry picked from commit 2b8b477) Co-authored-by: Justin Applegate <70449145+Legoclones@users.noreply.github.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
|
GH-135383 is a backport of this pull request to the 3.13 branch. |
lkollar
pushed a commit
to lkollar/cpython
that referenced
this pull request
Jun 19, 2025
…ent > 0x7fffffff in pickle (pythonGH-135322) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Pranjal095
pushed a commit
to Pranjal095/cpython
that referenced
this pull request
Jul 12, 2025
…ent > 0x7fffffff in pickle (pythonGH-135322) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
taegyunkim
pushed a commit
to taegyunkim/cpython
that referenced
this pull request
Aug 4, 2025
…ent > 0x7fffffff in pickle (pythonGH-135322) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Agent-Hellboy
pushed a commit
to Agent-Hellboy/cpython
that referenced
this pull request
Aug 19, 2025
…ent > 0x7fffffff in pickle (pythonGH-135322) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
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.
I changed the data type to
intfromPy_ssize_tfor thesizevariable. This variable is also used as an argument to 3 other functions but should be auto-casted (similar toload_counted_long). I also changed the error message to match the error message in the Pythonload_binstring()function.I would like to add tests for this specific case, but the payload that would show whether or not it works as intended requires a 2GB large pickle, and I'm not sure if you'd like that to be in the tests. Let me know what you think.
BINSTRINGincorrect data type for size #135321