Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7763c68

Browse files
committed
merge 3.4
2 parents a7c7817 + ff0f322 commit 7763c68

2 files changed

Lines changed: 12 additions & 16 deletions

File tree

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,8 @@ Library
444444
lines from the code object, fixing an issue when a lambda function is used as
445445
decorator argument. Patch by Thomas Ballinger and Allison Kaptur.
446446

447+
- Fix possible integer overflows in the pickle module.
448+
447449
- Issue #22931: Allow '[' and ']' in cookie values.
448450

449451
- The keywords attribute of functools.partial is now always a dictionary.

Modules/_pickle.c

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,7 @@ Pdata_grow(Pdata *self)
439439
if (new_allocated > (size_t)PY_SSIZE_T_MAX - allocated)
440440
goto nomemory;
441441
new_allocated += allocated;
442-
if (new_allocated > ((size_t)PY_SSIZE_T_MAX / sizeof(PyObject *)))
443-
goto nomemory;
444-
data = PyMem_REALLOC(data, new_allocated * sizeof(PyObject *));
442+
PyMem_RESIZE(data, PyObject *, new_allocated);
445443
if (data == NULL)
446444
goto nomemory;
447445

@@ -671,7 +669,7 @@ PyMemoTable_Copy(PyMemoTable *self)
671669
/* The table we get from _New() is probably smaller than we wanted.
672670
Free it and allocate one that's the right size. */
673671
PyMem_FREE(new->mt_table);
674-
new->mt_table = PyMem_MALLOC(self->mt_allocated * sizeof(PyMemoEntry));
672+
new->mt_table = PyMem_NEW(PyMemoEntry, self->mt_allocated);
675673
if (new->mt_table == NULL) {
676674
PyMem_FREE(new);
677675
PyErr_NoMemory();
@@ -766,7 +764,7 @@ _PyMemoTable_ResizeTable(PyMemoTable *self, Py_ssize_t min_size)
766764

767765
/* Allocate new table. */
768766
oldtable = self->mt_table;
769-
self->mt_table = PyMem_MALLOC(new_size * sizeof(PyMemoEntry));
767+
self->mt_table = PyMem_NEW(PyMemoEntry, new_size);
770768
if (self->mt_table == NULL) {
771769
self->mt_table = oldtable;
772770
PyErr_NoMemory();
@@ -1272,16 +1270,14 @@ static int
12721270
_Unpickler_ResizeMemoList(UnpicklerObject *self, Py_ssize_t new_size)
12731271
{
12741272
Py_ssize_t i;
1275-
PyObject **memo;
12761273

12771274
assert(new_size > self->memo_size);
12781275

1279-
memo = PyMem_REALLOC(self->memo, new_size * sizeof(PyObject *));
1280-
if (memo == NULL) {
1276+
PyMem_RESIZE(self->memo, PyObject *, new_size);
1277+
if (self->memo == NULL) {
12811278
PyErr_NoMemory();
12821279
return -1;
12831280
}
1284-
self->memo = memo;
12851281
for (i = self->memo_size; i < new_size; i++)
12861282
self->memo[i] = NULL;
12871283
self->memo_size = new_size;
@@ -1325,7 +1321,7 @@ _Unpickler_MemoPut(UnpicklerObject *self, Py_ssize_t idx, PyObject *value)
13251321
static PyObject **
13261322
_Unpickler_NewMemo(Py_ssize_t new_size)
13271323
{
1328-
PyObject **memo = PyMem_MALLOC(new_size * sizeof(PyObject *));
1324+
PyObject **memo = PyMem_NEW(PyObject *, new_size);
13291325
if (memo == NULL) {
13301326
PyErr_NoMemory();
13311327
return NULL;
@@ -6032,7 +6028,6 @@ load_mark(UnpicklerObject *self)
60326028

60336029
if ((self->num_marks + 1) >= self->marks_size) {
60346030
size_t alloc;
6035-
Py_ssize_t *marks;
60366031

60376032
/* Use the size_t type to check for overflow. */
60386033
alloc = ((size_t)self->num_marks << 1) + 20;
@@ -6043,15 +6038,14 @@ load_mark(UnpicklerObject *self)
60436038
}
60446039

60456040
if (self->marks == NULL)
6046-
marks = (Py_ssize_t *) PyMem_Malloc(alloc * sizeof(Py_ssize_t));
6041+
self->marks = PyMem_NEW(Py_ssize_t, alloc);
60476042
else
6048-
marks = (Py_ssize_t *) PyMem_Realloc(self->marks,
6049-
alloc * sizeof(Py_ssize_t));
6050-
if (marks == NULL) {
6043+
PyMem_RESIZE(self->marks, Py_ssize_t, alloc);
6044+
if (self->marks == NULL) {
6045+
self->marks_size = 0;
60516046
PyErr_NoMemory();
60526047
return -1;
60536048
}
6054-
self->marks = marks;
60556049
self->marks_size = (Py_ssize_t)alloc;
60566050
}
60576051

0 commit comments

Comments
 (0)