Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
c5fa9920
Commit
c5fa9920
authored
Oct 06, 2004
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Armin's patch to prevent overflows.
parent
f7948c25
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
7 deletions
+22
-7
Modules/collectionsmodule.c
Modules/collectionsmodule.c
+22
-7
No files found.
Modules/collectionsmodule.c
View file @
c5fa9920
...
...
@@ -52,8 +52,21 @@ typedef struct BLOCK {
}
block
;
static
block
*
newblock
(
block
*
leftlink
,
block
*
rightlink
)
{
block
*
b
=
PyMem_Malloc
(
sizeof
(
block
));
newblock
(
block
*
leftlink
,
block
*
rightlink
,
int
len
)
{
block
*
b
;
/* To prevent len from overflowing INT_MAX on 64-bit machines, we
* refuse to allocate new blocks if the current len is dangerously
* close. There is some extra margin to prevent spurious arithmetic
* overflows at various places. The following check ensures that
* the blocks allocated to the deque, in the worst case, can only
* have INT_MAX-2 entries in total.
*/
if
(
len
>=
INT_MAX
-
2
*
BLOCKLEN
)
{
PyErr_SetString
(
PyExc_OverflowError
,
"cannot add more blocks to the deque"
);
return
NULL
;
}
b
=
PyMem_Malloc
(
sizeof
(
block
));
if
(
b
==
NULL
)
{
PyErr_NoMemory
();
return
NULL
;
...
...
@@ -87,7 +100,7 @@ deque_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if
(
deque
==
NULL
)
return
NULL
;
b
=
newblock
(
NULL
,
NULL
);
b
=
newblock
(
NULL
,
NULL
,
0
);
if
(
b
==
NULL
)
{
Py_DECREF
(
deque
);
return
NULL
;
...
...
@@ -110,7 +123,7 @@ deque_append(dequeobject *deque, PyObject *item)
{
deque
->
state
++
;
if
(
deque
->
rightindex
==
BLOCKLEN
-
1
)
{
block
*
b
=
newblock
(
deque
->
rightblock
,
NULL
);
block
*
b
=
newblock
(
deque
->
rightblock
,
NULL
,
deque
->
len
);
if
(
b
==
NULL
)
return
NULL
;
assert
(
deque
->
rightblock
->
rightlink
==
NULL
);
...
...
@@ -132,7 +145,7 @@ deque_appendleft(dequeobject *deque, PyObject *item)
{
deque
->
state
++
;
if
(
deque
->
leftindex
==
0
)
{
block
*
b
=
newblock
(
NULL
,
deque
->
leftblock
);
block
*
b
=
newblock
(
NULL
,
deque
->
leftblock
,
deque
->
len
);
if
(
b
==
NULL
)
return
NULL
;
assert
(
deque
->
leftblock
->
leftlink
==
NULL
);
...
...
@@ -235,7 +248,8 @@ deque_extend(dequeobject *deque, PyObject *iterable)
while
((
item
=
PyIter_Next
(
it
))
!=
NULL
)
{
deque
->
state
++
;
if
(
deque
->
rightindex
==
BLOCKLEN
-
1
)
{
block
*
b
=
newblock
(
deque
->
rightblock
,
NULL
);
block
*
b
=
newblock
(
deque
->
rightblock
,
NULL
,
deque
->
len
);
if
(
b
==
NULL
)
{
Py_DECREF
(
item
);
Py_DECREF
(
it
);
...
...
@@ -271,7 +285,8 @@ deque_extendleft(dequeobject *deque, PyObject *iterable)
while
((
item
=
PyIter_Next
(
it
))
!=
NULL
)
{
deque
->
state
++
;
if
(
deque
->
leftindex
==
0
)
{
block
*
b
=
newblock
(
NULL
,
deque
->
leftblock
);
block
*
b
=
newblock
(
NULL
,
deque
->
leftblock
,
deque
->
len
);
if
(
b
==
NULL
)
{
Py_DECREF
(
item
);
Py_DECREF
(
it
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment