summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-08-29 22:27:10 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-08-29 22:27:10 (GMT)
commit55549ec476c178ca4723ba97d4f00a015f427427 (patch)
tree43dee50c756d4a81c23efcc254a703d6425d1fb2 /Lib
parent82be19f889e97618d73f405ad53ceffbee462008 (diff)
downloadcpython-55549ec476c178ca4723ba97d4f00a015f427427.zip
cpython-55549ec476c178ca4723ba97d4f00a015f427427.tar.gz
cpython-55549ec476c178ca4723ba97d4f00a015f427427.tar.bz2
Issue #12847: Fix a crash with negative PUT and LONG_BINPUT arguments in
the C pickle implementation.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/pickle.py6
-rw-r--r--Lib/test/pickletester.py12
2 files changed, 18 insertions, 0 deletions
diff --git a/Lib/pickle.py b/Lib/pickle.py
index aca8fd1..32ae02b 100644
--- a/Lib/pickle.py
+++ b/Lib/pickle.py
@@ -1156,16 +1156,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
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py
index 2b1fdd2..6dc2b5b 100644
--- a/Lib/test/pickletester.py
+++ b/Lib/test/pickletester.py
@@ -1121,6 +1121,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\x03X\xff\xff\xff\xffxyzq\x00.')
+ def test_negative_put(self):
+ # Issue #12847
+ dumped = b'Va\np-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\x03X\x01\x00\x00\x00ar\xff\xff\xff\xff.'
+ self.assertRaises(ValueError, self.loads, dumped)
+
class BigmemPickleTests(unittest.TestCase):