diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-11-25 13:07:36 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-11-25 13:07:36 (GMT) |
commit | 14128d8bc5e8f9e6f0234f47984fb7ca5167b082 (patch) | |
tree | 7211e5861e90e1e551e3e85335ec0d3281d220ea /Modules/_pickle.c | |
parent | e5beb3da00d4d66d9af70eb97540e4f853d3f0d9 (diff) | |
parent | c5f3b4285a8f3f90305d777a88a856a623c22cb1 (diff) | |
download | cpython-14128d8bc5e8f9e6f0234f47984fb7ca5167b082.zip cpython-14128d8bc5e8f9e6f0234f47984fb7ca5167b082.tar.gz cpython-14128d8bc5e8f9e6f0234f47984fb7ca5167b082.tar.bz2 |
Issue #25725: Fixed a reference leak in pickle.loads() when unpickling
invalid data including tuple instructions.
Diffstat (limited to 'Modules/_pickle.c')
-rw-r--r-- | Modules/_pickle.c | 27 |
1 files changed, 8 insertions, 19 deletions
diff --git a/Modules/_pickle.c b/Modules/_pickle.c index 8b04fa5..c22b6c8 100644 --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -5047,15 +5047,14 @@ load_counted_binunicode(UnpicklerObject *self, int nbytes) } static int -load_tuple(UnpicklerObject *self) +load_counted_tuple(UnpicklerObject *self, int len) { PyObject *tuple; - Py_ssize_t i; - if ((i = marker(self)) < 0) - return -1; + if (Py_SIZE(self->stack) < len) + return stack_underflow(); - tuple = Pdata_poptuple(self->stack, i); + tuple = Pdata_poptuple(self->stack, Py_SIZE(self->stack) - len); if (tuple == NULL) return -1; PDATA_PUSH(self->stack, tuple, -1); @@ -5063,24 +5062,14 @@ load_tuple(UnpicklerObject *self) } static int -load_counted_tuple(UnpicklerObject *self, int len) +load_tuple(UnpicklerObject *self) { - PyObject *tuple; + Py_ssize_t i; - tuple = PyTuple_New(len); - if (tuple == NULL) + if ((i = marker(self)) < 0) return -1; - while (--len >= 0) { - PyObject *item; - - PDATA_POP(self->stack, item); - if (item == NULL) - return -1; - PyTuple_SET_ITEM(tuple, len, item); - } - PDATA_PUSH(self->stack, tuple, -1); - return 0; + return load_counted_tuple(self, Py_SIZE(self->stack) - i); } static int |