diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-07-17 08:35:35 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-07-17 08:35:35 (GMT) |
commit | 3410c01d83d70ceef48b735c247aebd2d5bd3411 (patch) | |
tree | 31bd2f79a937309132d92e75ae53c25d5309bbbd /Lib/pickle.py | |
parent | fb2125daf35f7f21d04b5c567c639c20b0565a9c (diff) | |
parent | dec25afab1c325c28621dda3ba2b32dbc200c8b3 (diff) | |
download | cpython-3410c01d83d70ceef48b735c247aebd2d5bd3411.zip cpython-3410c01d83d70ceef48b735c247aebd2d5bd3411.tar.gz cpython-3410c01d83d70ceef48b735c247aebd2d5bd3411.tar.bz2 |
Issue #17711: Fixed unpickling by the persistent ID with protocol 0.
Original patch by Alexandre Vassalotti.
Diffstat (limited to 'Lib/pickle.py')
-rw-r--r-- | Lib/pickle.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/Lib/pickle.py b/Lib/pickle.py index 963b595..c8370c9 100644 --- a/Lib/pickle.py +++ b/Lib/pickle.py @@ -530,7 +530,11 @@ class _Pickler: self.save(pid, save_persistent_id=False) self.write(BINPERSID) else: - self.write(PERSID + str(pid).encode("ascii") + b'\n') + try: + self.write(PERSID + str(pid).encode("ascii") + b'\n') + except UnicodeEncodeError: + raise PicklingError( + "persistent IDs in protocol 0 must be ASCII strings") def save_reduce(self, func, args, state=None, listitems=None, dictitems=None, obj=None): @@ -1074,7 +1078,11 @@ class _Unpickler: dispatch[FRAME[0]] = load_frame def load_persid(self): - pid = self.readline()[:-1].decode("ascii") + try: + pid = self.readline()[:-1].decode("ascii") + except UnicodeDecodeError: + raise UnpicklingError( + "persistent IDs in protocol 0 must be ASCII strings") self.append(self.persistent_load(pid)) dispatch[PERSID[0]] = load_persid |