Skip to content

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Lib/test/pickletester.py
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,11 @@ def test_large_32b_binunicode8(self):
self.check_unpickling_error((pickle.UnpicklingError, OverflowError),
dumped)

def test_large_binstring(self):
errmsg = '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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Raise a correct exception for values greater than 0x7fffffff for the ``BINSTRING`` opcode in the C implementation of :mod:`pickle`.
9 changes: 4 additions & 5 deletions Modules/_pickle.c
Original file line number Diff line number Diff line change
Expand Up @@ -5543,17 +5543,16 @@ static int
load_counted_binstring(PickleState *st, UnpicklerObject *self, int nbytes)
{
PyObject *obj;
Py_ssize_t size;
long size;
char *s;

if (_Unpickler_Read(self, st, &s, nbytes) < 0)
return -1;

size = calc_binsize(s, nbytes);
size = calc_binint(s, nbytes);
if (size < 0) {
PyErr_Format(st->UnpicklingError,
"BINSTRING exceeds system's maximum size of %zd bytes",
PY_SSIZE_T_MAX);
PyErr_SetString(st->UnpicklingError,
"BINSTRING pickle has negative byte count");
return -1;
}

Expand Down
Loading