-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-135321: Changing data type of size
variable for BINSTRING
in _pickle
#135322
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-135321: Changing data type of size
variable for BINSTRING
in _pickle
#135322
Conversation
…opcode `BINSTRING` to `int` from `Py_ssize_t`
size
variable for C implementation of pickle …size
variable for BINSTRING
in _pickle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]>
Co-authored-by: Serhiy Storchaka <[email protected]>
I made all the requested changes - thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Thanks @Legoclones for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
…ent > 0x7fffffff in pickle (pythonGH-135322) (cherry picked from commit 2b8b477) Co-authored-by: Justin Applegate <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]>
GH-135382 is a backport of this pull request to the 3.14 branch. |
…ent > 0x7fffffff in pickle (pythonGH-135322) (cherry picked from commit 2b8b4774d29a707330d463f226630185cbd3ceff) Co-authored-by: Justin Applegate <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]>
GH-135383 is a backport of this pull request to the 3.13 branch. |
…ment > 0x7fffffff in pickle (GH-135322) (GH-135383) (cherry picked from commit 2b8b477) Co-authored-by: Justin Applegate <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]>
…ment > 0x7fffffff in pickle (GH-135322) (GH-135382) (cherry picked from commit 2b8b477) Co-authored-by: Justin Applegate <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]>
I changed the data type to
int
fromPy_ssize_t
for thesize
variable. 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.
BINSTRING
incorrect data type for size #135321