summaryrefslogtreecommitdiffstats
path: root/Lib/codecs.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-09-10 17:41:19 (GMT)
committerGitHub <noreply@github.com>2023-09-10 17:41:19 (GMT)
commitb070d73ff20df210eb41e3e5104ba6c355d9584e (patch)
treec44d9271c15aff1dab742ab44b14a9420313c33d /Lib/codecs.py
parentc20658249da47408c2d2455de87d7e70445cf3f0 (diff)
downloadcpython-b070d73ff20df210eb41e3e5104ba6c355d9584e.zip
cpython-b070d73ff20df210eb41e3e5104ba6c355d9584e.tar.gz
cpython-b070d73ff20df210eb41e3e5104ba6c355d9584e.tar.bz2
[3.11] gh-50644: Forbid pickling of codecs streams (GH-109180) (GH-109232)
Attempts to pickle or create a shallow or deep copy of codecs streams now raise a TypeError. Previously, copying failed with a RecursionError, while pickling produced wrong results that eventually caused unpickling to fail with a RecursionError. (cherry picked from commit d6892c2b9263b39ea1c7905667942914b6a24b2c) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/codecs.py')
-rw-r--r--Lib/codecs.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/codecs.py b/Lib/codecs.py
index 3b173b6..c6165fc 100644
--- a/Lib/codecs.py
+++ b/Lib/codecs.py
@@ -414,6 +414,9 @@ class StreamWriter(Codec):
def __exit__(self, type, value, tb):
self.stream.close()
+ def __reduce_ex__(self, proto):
+ raise TypeError("can't serialize %s" % self.__class__.__name__)
+
###
class StreamReader(Codec):
@@ -663,6 +666,9 @@ class StreamReader(Codec):
def __exit__(self, type, value, tb):
self.stream.close()
+ def __reduce_ex__(self, proto):
+ raise TypeError("can't serialize %s" % self.__class__.__name__)
+
###
class StreamReaderWriter:
@@ -750,6 +756,9 @@ class StreamReaderWriter:
def __exit__(self, type, value, tb):
self.stream.close()
+ def __reduce_ex__(self, proto):
+ raise TypeError("can't serialize %s" % self.__class__.__name__)
+
###
class StreamRecoder:
@@ -866,6 +875,9 @@ class StreamRecoder:
def __exit__(self, type, value, tb):
self.stream.close()
+ def __reduce_ex__(self, proto):
+ raise TypeError("can't serialize %s" % self.__class__.__name__)
+
### Shortcuts
def open(filename, mode='r', encoding=None, errors='strict', buffering=-1):