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
a514eb95
Commit
a514eb95
authored
Aug 30, 2011
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Plain Diff
Issue #12847: Fix a crash with negative PUT and LONG_BINPUT arguments in
the C pickle implementation.
parents
ee763e2a
55549ec4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
1 deletion
+31
-1
Lib/pickle.py
Lib/pickle.py
+6
-0
Lib/test/pickletester.py
Lib/test/pickletester.py
+12
-0
Misc/NEWS
Misc/NEWS
+3
-0
Modules/_pickle.c
Modules/_pickle.c
+10
-1
No files found.
Lib/pickle.py
View file @
a514eb95
...
...
@@ -1154,16 +1154,22 @@ class _Unpickler:
def
load_put
(
self
):
i
=
int
(
self
.
readline
()[:
-
1
])
if
i
<
0
:
raise
ValueError
(
"negative PUT argument"
)
self
.
memo
[
i
]
=
self
.
stack
[
-
1
]
dispatch
[
PUT
[
0
]]
=
load_put
def
load_binput
(
self
):
i
=
self
.
read
(
1
)[
0
]
if
i
<
0
:
raise
ValueError
(
"negative BINPUT argument"
)
self
.
memo
[
i
]
=
self
.
stack
[
-
1
]
dispatch
[
BINPUT
[
0
]]
=
load_binput
def
load_long_binput
(
self
):
i
=
mloads
(
b'i'
+
self
.
read
(
4
))
if
i
<
0
:
raise
ValueError
(
"negative LONG_BINPUT argument"
)
self
.
memo
[
i
]
=
self
.
stack
[
-
1
]
dispatch
[
LONG_BINPUT
[
0
]]
=
load_long_binput
...
...
Lib/test/pickletester.py
View file @
a514eb95
...
...
@@ -1150,6 +1150,18 @@ class AbstractPickleTests(unittest.TestCase):
# On 32-bit builds, a BINUNICODE of 2**31 or more is refused
self
.
check_negative_32b_binXXX
(
b'
\
x80
\
x03
X
\
xff
\
xff
\
xff
\
xff
xyzq
\
x00
.'
)
def
test_negative_put
(
self
):
# Issue #12847
dumped
=
b'Va
\
n
p-1
\
n
.'
self
.
assertRaises
(
ValueError
,
self
.
loads
,
dumped
)
def
test_negative_32b_binput
(
self
):
# Issue #12847
if
sys
.
maxsize
>
2
**
32
:
self
.
skipTest
(
"test is only meaningful on 32-bit builds"
)
dumped
=
b'
\
x80
\
x03
X
\
x01
\
x00
\
x00
\
x00
ar
\
xff
\
xff
\
xff
\
xff
.'
self
.
assertRaises
(
ValueError
,
self
.
loads
,
dumped
)
class
BigmemPickleTests
(
unittest
.
TestCase
):
...
...
Misc/NEWS
View file @
a514eb95
...
...
@@ -268,6 +268,9 @@ Core and Builtins
Library
-------
- Issue #12847: Fix a crash with negative PUT and LONG_BINPUT arguments in
the C pickle implementation.
- Issue #11564: Avoid crashes when trying to pickle huge objects or containers
(more than 2**31 items). Instead, in most cases, an OverflowError is raised.
...
...
Modules/_pickle.c
View file @
a514eb95
...
...
@@ -4873,8 +4873,12 @@ load_put(UnpicklerObject *self)
return
-
1
;
idx
=
PyLong_AsSsize_t
(
key
);
Py_DECREF
(
key
);
if
(
idx
==
-
1
&&
PyErr_Occurred
())
if
(
idx
<
0
)
{
if
(
!
PyErr_Occurred
())
PyErr_SetString
(
PyExc_ValueError
,
"negative PUT argument"
);
return
-
1
;
}
return
_Unpickler_MemoPut
(
self
,
idx
,
value
);
}
...
...
@@ -4913,6 +4917,11 @@ load_long_binput(UnpicklerObject *self)
value
=
self
->
stack
->
data
[
Py_SIZE
(
self
->
stack
)
-
1
];
idx
=
calc_binsize
(
s
,
4
);
if
(
idx
<
0
)
{
PyErr_SetString
(
PyExc_ValueError
,
"negative LONG_BINPUT argument"
);
return
-
1
;
}
return
_Unpickler_MemoPut
(
self
,
idx
,
value
);
}
...
...
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