Martin Panter added the comment: Stream reader interfaces suffer the same problem. Test cases:
codecs.getreader("unicode-escape")(BytesIO(br"\u2013")).read(1) codecs.getreader("hex-codec")(BytesIO(b"33")).read(1) codecs.getreader("base64-codec")(BytesIO(b"AA==")).read(1) TestCase().assertEqual(b"=", codecs.getreader("quopri-codec")(BytesIO(b"=3D")).read(1)) Even though the “zlib” incremental decoder is okay, its stream reader still suffers this problem. I was going to check for zip bomb behaviour when you call read() with a limited number of input “characters”, but got this instead: >>> codecs.getreader("zlib-codec")(bomb).read(1, 1) zlib.error: Error -5 while decompressing data: incomplete or truncated stream Similar problems with stream writers, for instance: >>> w = codecs.getwriter("base64-codec")(BytesIO()) >>> w.write(b"1"); w.write(b"2"); w.reset(); w.getvalue() b'MQ==\nMg==\n' # Should be b"MTI=\n" I also noticed StreamWriter.writelines() assumes it is encoding text, and does not work at least with “base64-codec”: >>>> codecs.getwriter("base64-codec")(BytesIO()).writelines((b"1", b"2")) TypeError: sequence item 0: expected str instance, bytes found ---------- versions: +Python 3.4 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue20132> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com