Message226679
| Author |
martin.panter |
| Recipients |
doerwalter, lemburg, loewis, martin.panter, ncoghlan, vstinner |
| Date |
2014年09月10日.05:16:56 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1410326217.24.0.956945864029.issue20132@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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 |
|