[Python-checkins] cpython (merge 3.4 -> default): Issue #22406: Fixed the uu_codec codec incorrectly ported to 3.x.
serhiy.storchaka
python-checkins at python.org
Fri Nov 7 13:12:47 CET 2014
https://hg.python.org/cpython/rev/b18ef4a3e7c1
changeset: 93428:b18ef4a3e7c1
parent: 93426:3e4f3cc4f1f9
parent: 93427:ad89a652b4ed
user: Serhiy Storchaka <storchaka at gmail.com>
date: Fri Nov 07 14:06:19 2014 +0200
summary:
Issue #22406: Fixed the uu_codec codec incorrectly ported to 3.x.
Based on patch by Martin Panter.
files:
Lib/encodings/uu_codec.py | 2 +-
Lib/test/test_codecs.py | 4 ++++
Lib/test/test_uu.py | 22 ++++++++++++++++++++++
Misc/NEWS | 3 +++
4 files changed, 30 insertions(+), 1 deletions(-)
diff --git a/Lib/encodings/uu_codec.py b/Lib/encodings/uu_codec.py
--- a/Lib/encodings/uu_codec.py
+++ b/Lib/encodings/uu_codec.py
@@ -54,7 +54,7 @@
data = binascii.a2b_uu(s)
except binascii.Error as v:
# Workaround for broken uuencoders by /Fredrik Lundh
- nbytes = (((ord(s[0])-32) & 63) * 4 + 5) / 3
+ nbytes = (((s[0]-32) & 63) * 4 + 5) // 3
data = binascii.a2b_uu(s[:nbytes])
#sys.stderr.write("Warning: %s\n" % str(v))
write(data)
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -2571,6 +2571,10 @@
info = codecs.lookup(alias)
self.assertEqual(info.name, expected_name)
+ def test_uu_invalid(self):
+ # Missing "begin" line
+ self.assertRaises(ValueError, codecs.decode, b"", "uu-codec")
+
# The codec system tries to wrap exceptions in order to ensure the error
# mentions the operation being performed and the codec involved. We
diff --git a/Lib/test/test_uu.py b/Lib/test/test_uu.py
--- a/Lib/test/test_uu.py
+++ b/Lib/test/test_uu.py
@@ -93,6 +93,28 @@
except uu.Error as e:
self.assertEqual(str(e), "No valid begin line found in input file")
+ def test_garbage_padding(self):
+ # Issue #22406
+ encodedtext = (
+ b"begin 644 file\n"
+ # length 1; bits 001100 111111 111111 111111
+ b"\x21\x2C\x5F\x5F\x5F\n"
+ b"\x20\n"
+ b"end\n"
+ )
+ plaintext = b"\x33" # 00110011
+
+ with self.subTest("uu.decode()"):
+ inp = io.BytesIO(encodedtext)
+ out = io.BytesIO()
+ uu.decode(inp, out, quiet=True)
+ self.assertEqual(out.getvalue(), plaintext)
+
+ with self.subTest("uu_codec"):
+ import codecs
+ decoded = codecs.decode(encodedtext, "uu_codec")
+ self.assertEqual(decoded, plaintext)
+
class UUStdIOTest(unittest.TestCase):
def setUp(self):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -183,6 +183,9 @@
Library
-------
+- Issue #22406: Fixed the uu_codec codec incorrectly ported to 3.x.
+ Based on patch by Martin Panter.
+
- Issue #17293: uuid.getnode() now determines MAC address on AIX using netstat.
Based on patch by Aivars Kalvāns.
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list