mirror of
https://github.com/python/cpython.git
synced 2025-07-07 11:25:30 +00:00
gh-135321: Always raise a correct exception for BINSTRING argument > 0x7fffffff in pickle (GH-135322)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
5ae669fc4e
commit
2b8b4774d2
3 changed files with 10 additions and 5 deletions
|
@ -1100,6 +1100,11 @@ class AbstractUnpickleTests:
|
|||
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)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Raise a correct exception for values greater than 0x7fffffff for the ``BINSTRING`` opcode in the C implementation of :mod:`pickle`.
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue