Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 85e7066

Browse files
Issue #22406: Fixed the uu_codec codec incorrectly ported to 3.x.
Based on patch by Martin Panter.
2 parents 57b9677 + 519114d commit 85e7066

4 files changed

Lines changed: 30 additions & 1 deletion

File tree

Lib/encodings/uu_codec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def uu_decode(input, errors='strict'):
5454
data = binascii.a2b_uu(s)
5555
except binascii.Error as v:
5656
# Workaround for broken uuencoders by /Fredrik Lundh
57-
nbytes = (((ord(s[0])-32) & 63) * 4 + 5) / 3
57+
nbytes = (((s[0]-32) & 63) * 4 + 5) // 3
5858
data = binascii.a2b_uu(s[:nbytes])
5959
#sys.stderr.write("Warning: %s\n" % str(v))
6060
write(data)

Lib/test/test_codecs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2571,6 +2571,10 @@ def test_aliases(self):
25712571
info = codecs.lookup(alias)
25722572
self.assertEqual(info.name, expected_name)
25732573

2574+
def test_uu_invalid(self):
2575+
# Missing "begin" line
2576+
self.assertRaises(ValueError, codecs.decode, b"", "uu-codec")
2577+
25742578

25752579
# The codec system tries to wrap exceptions in order to ensure the error
25762580
# mentions the operation being performed and the codec involved. We

Lib/test/test_uu.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,28 @@ def test_missingbegin(self):
9393
except uu.Error as e:
9494
self.assertEqual(str(e), "No valid begin line found in input file")
9595

96+
def test_garbage_padding(self):
97+
# Issue #22406
98+
encodedtext = (
99+
b"begin 644 file\n"
100+
# length 1; bits 001100 111111 111111 111111
101+
b"\x21\x2C\x5F\x5F\x5F\n"
102+
b"\x20\n"
103+
b"end\n"
104+
)
105+
plaintext = b"\x33" # 00110011
106+
107+
with self.subTest("uu.decode()"):
108+
inp = io.BytesIO(encodedtext)
109+
out = io.BytesIO()
110+
uu.decode(inp, out, quiet=True)
111+
self.assertEqual(out.getvalue(), plaintext)
112+
113+
with self.subTest("uu_codec"):
114+
import codecs
115+
decoded = codecs.decode(encodedtext, "uu_codec")
116+
self.assertEqual(decoded, plaintext)
117+
96118
class UUStdIOTest(unittest.TestCase):
97119

98120
def setUp(self):

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ Core and Builtins
183183
Library
184184
-------
185185

186+
- Issue #22406: Fixed the uu_codec codec incorrectly ported to 3.x.
187+
Based on patch by Martin Panter.
188+
186189
- Issue #17293: uuid.getnode() now determines MAC address on AIX using netstat.
187190
Based on patch by Aivars Kalvāns.
188191

0 commit comments

Comments
 (0)