diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2023-09-10 17:06:09 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-10 17:06:09 (GMT) |
commit | d6892c2b9263b39ea1c7905667942914b6a24b2c (patch) | |
tree | 26857f7693712248ae06996a024659a1c73bb51f /Lib/codecs.py | |
parent | 71b6e2602c0b5b06d51855f179cdb30094a67968 (diff) | |
download | cpython-d6892c2b9263b39ea1c7905667942914b6a24b2c.zip cpython-d6892c2b9263b39ea1c7905667942914b6a24b2c.tar.gz cpython-d6892c2b9263b39ea1c7905667942914b6a24b2c.tar.bz2 |
gh-50644: Forbid pickling of codecs streams (GH-109180)
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.
Diffstat (limited to 'Lib/codecs.py')
-rw-r--r-- | Lib/codecs.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/codecs.py b/Lib/codecs.py index c1c55d8..82f2398 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): |