| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + Fix bugs in :mod:`pickle` where exceptions could be overwritten. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1139,10 +1139,13 @@ _Pickler_New(void) | |||
| 1139 | 1139 | self->reducer_override = NULL; | |
| 1140 | 1140 | ||
| 1141 | 1141 | self->memo = PyMemoTable_New(); | |
| 1142 | + if (self->memo == NULL) { | ||
| 1143 | + Py_DECREF(self); | ||
| 1144 | + return NULL; | ||
| 1145 | + } | ||
| 1142 | 1146 | self->output_buffer = PyBytes_FromStringAndSize(NULL, | |
| 1143 | 1147 | self->max_output_len); | |
| 1144 | - | ||
| 1145 | - if (self->memo == NULL || self->output_buffer == NULL) { | ||
| 1148 | + if (self->output_buffer == NULL) { | ||
| 1146 | 1149 | Py_DECREF(self); | |
| 1147 | 1150 | return NULL; | |
| 1148 | 1151 | } | |
@@ -1627,9 +1630,12 @@ _Unpickler_New(void) | |||
| 1627 | 1630 | self->memo_size = 32; | |
| 1628 | 1631 | self->memo_len = 0; | |
| 1629 | 1632 | self->memo = _Unpickler_NewMemo(self->memo_size); | |
| 1633 | + if (self->memo == NULL) { | ||
| 1634 | + Py_DECREF(self); | ||
| 1635 | + return NULL; | ||
| 1636 | + } | ||
| 1630 | 1637 | self->stack = (Pdata *)Pdata_New(); | |
| 1631 | - | ||
| 1632 | - if (self->memo == NULL || self->stack == NULL) { | ||
| 1638 | + if (self->stack == NULL) { | ||
| 1633 | 1639 | Py_DECREF(self); | |
| 1634 | 1640 | return NULL; | |
| 1635 | 1641 | } | |
@@ -4833,11 +4839,12 @@ _pickle_PicklerMemoProxy_copy_impl(PicklerMemoProxyObject *self) | |||
| 4833 | 4839 | PyObject *key, *value; | |
| 4834 | 4840 | ||
| 4835 | 4841 | key = PyLong_FromVoidPtr(entry.me_key); | |
| 4842 | + if (key == NULL) { | ||
| 4843 | + goto error; | ||
| 4844 | + } | ||
| 4836 | 4845 | value = Py_BuildValue("nO", entry.me_value, entry.me_key); | |
| 4837 | - | ||
| 4838 | - if (key == NULL || value == NULL) { | ||
| 4839 | - Py_XDECREF(key); | ||
| 4840 | - Py_XDECREF(value); | ||
| 4846 | + if (value == NULL) { | ||
| 4847 | + Py_DECREF(key); | ||
| 4841 | 4848 | goto error; | |
| 4842 | 4849 | } | |
| 4843 | 4850 | status = PyDict_SetItem(new_memo, key, value); | |
@@ -6033,13 +6040,21 @@ load_stack_global(UnpicklerObject *self) | |||
| 6033 | 6040 | PyObject *global_name; | |
| 6034 | 6041 | ||
| 6035 | 6042 | PDATA_POP(self->stack, global_name); | |
| 6043 | + if (global_name == NULL) { | ||
| 6044 | + return -1; | ||
| 6045 | + } | ||
| 6036 | 6046 | PDATA_POP(self->stack, module_name); | |
| 6037 | - if (module_name == NULL || !PyUnicode_CheckExact(module_name) || | ||
| 6038 | - global_name == NULL || !PyUnicode_CheckExact(global_name)) { | ||
| 6047 | + if (module_name == NULL) { | ||
| 6048 | + Py_DECREF(global_name); | ||
| 6049 | + return -1; | ||
| 6050 | + } | ||
| 6051 | + if (!PyUnicode_CheckExact(module_name) || | ||
| 6052 | + !PyUnicode_CheckExact(global_name)) | ||
| 6053 | + { | ||
| 6039 | 6054 | PickleState *st = _Pickle_GetGlobalState(); | |
| 6040 | 6055 | PyErr_SetString(st->UnpicklingError, "STACK_GLOBAL requires str"); | |
| 6041 | - Py_XDECREF(global_name); | ||
| 6042 | - Py_XDECREF(module_name); | ||
| 6056 | + Py_DECREF(global_name); | ||
| 6057 | + Py_DECREF(module_name); | ||
| 6043 | 6058 | return -1; | |
| 6044 | 6059 | } | |
| 6045 | 6060 | global = find_class(self, module_name, global_name); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments