summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-11-07 12:04:37 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-11-07 12:04:37 (GMT)
commit519114df4258f17bc33a31c6c1614fd82e2ab0be (patch)
tree4f29d5972347ee48ec81fd6219e79fcdd5464d45
parente66bb9692977c66ffcbe9af64642ab5977879a9a (diff)
downloadcpython-519114df4258f17bc33a31c6c1614fd82e2ab0be.zip
cpython-519114df4258f17bc33a31c6c1614fd82e2ab0be.tar.gz
cpython-519114df4258f17bc33a31c6c1614fd82e2ab0be.tar.bz2
Issue #22406: Fixed the uu_codec codec incorrectly ported to 3.x.
Based on patch by Martin Panter.
-rw-r--r--Lib/encodings/uu_codec.py2
-rw-r--r--Lib/test/test_codecs.py4
-rw-r--r--Lib/test/test_uu.py22
-rw-r--r--Misc/NEWS3
4 files changed, 30 insertions, 1 deletions
diff --git a/Lib/encodings/uu_codec.py b/Lib/encodings/uu_codec.py
index 1454095..2a5728f 100644
--- a/Lib/encodings/uu_codec.py
+++ b/Lib/encodings/uu_codec.py
@@ -54,7 +54,7 @@ def uu_decode(input, errors='strict'):
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
index 856126c..d4a0660 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -2563,6 +2563,10 @@ class TransformCodecTest(unittest.TestCase):
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
index cbf6724..25fffbf 100644
--- a/Lib/test/test_uu.py
+++ b/Lib/test/test_uu.py
@@ -93,6 +93,28 @@ class UUTest(unittest.TestCase):
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
index 452fed3..c59cd1a 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -36,6 +36,9 @@ Core and Builtins
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.