summaryrefslogtreecommitdiff
path: root/Lib/pickle.py
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@microsoft.com>2017-02-04 15:05:50 -0800
committerSteve Dower <steve.dower@microsoft.com>2017-02-04 15:05:50 -0800
commit3b0e4320092ac0504b6670cafaf0301b908c91fc (patch)
treed3be1b6b844d61763bb366fa21ceed475e5703fd /Lib/pickle.py
parentb2fa705fd3887c326e811c418469c784353027f4 (diff)
parentf687fbcd73c14dfcbe086eb5cd94b298f1e81e72 (diff)
downloadcpython-3b0e4320092ac0504b6670cafaf0301b908c91fc.tar.gz
Issue #29392: Prevent crash when passing invalid arguments into msvcrt module.
Diffstat (limited to 'Lib/pickle.py')
-rw-r--r--Lib/pickle.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/Lib/pickle.py b/Lib/pickle.py
index c8370c9f7e..702b0b35ce 100644
--- a/Lib/pickle.py
+++ b/Lib/pickle.py
@@ -1464,12 +1464,19 @@ class _Unpickler:
def load_appends(self):
items = self.pop_mark()
list_obj = self.stack[-1]
- if isinstance(list_obj, list):
- list_obj.extend(items)
+ try:
+ extend = list_obj.extend
+ except AttributeError:
+ pass
else:
- append = list_obj.append
- for item in items:
- append(item)
+ extend(items)
+ return
+ # Even if the PEP 307 requires extend() and append() methods,
+ # fall back on append() if the object has no extend() method
+ # for backward compatibility.
+ append = list_obj.append
+ for item in items:
+ append(item)
dispatch[APPENDS[0]] = load_appends
def load_setitem(self):