]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-39055: Reject a trailing \n in base64.b64decode() with validate=True. (GH-17616)
authorSerhiy Storchaka <storchaka@gmail.com>
Sun, 5 Jan 2020 12:15:50 +0000 (14:15 +0200)
committerGitHub <noreply@github.com>
Sun, 5 Jan 2020 12:15:50 +0000 (14:15 +0200)
Lib/base64.py
Lib/test/test_base64.py
Misc/NEWS.d/next/Library/2019-12-15-19-23-23.bpo-39055.FmN3un.rst [new file with mode: 0644]

index 2be9c395a96674718fd51d5afe716598e577b8aa..2e70223dfe78244739be541c439f64e4f6acb28f 100755 (executable)
@@ -82,7 +82,7 @@ def b64decode(s, altchars=None, validate=False):
         altchars = _bytes_from_decode_data(altchars)
         assert len(altchars) == 2, repr(altchars)
         s = s.translate(bytes.maketrans(altchars, b'+/'))
-    if validate and not re.match(b'^[A-Za-z0-9+/]*={0,2}$', s):
+    if validate and not re.fullmatch(b'[A-Za-z0-9+/]*={0,2}', s):
         raise binascii.Error('Non-base64 digit found')
     return binascii.a2b_base64(s)
 
index 2a4cc2acad24b1b32c6d91aca27db9748edeee90..7dba6635d4eae7bffa79d41c66d96298b0d837bf 100644 (file)
@@ -250,6 +250,7 @@ class BaseXYTestCase(unittest.TestCase):
                  (b'3d}==', b'\xdd'),
                  (b'@@', b''),
                  (b'!', b''),
+                 (b"YWJj\n", b"abc"),
                  (b'YWJj\nYWI=', b'abcab'))
         funcs = (
             base64.b64decode,
diff --git a/Misc/NEWS.d/next/Library/2019-12-15-19-23-23.bpo-39055.FmN3un.rst b/Misc/NEWS.d/next/Library/2019-12-15-19-23-23.bpo-39055.FmN3un.rst
new file mode 100644 (file)
index 0000000..83b1431
--- /dev/null
@@ -0,0 +1,2 @@
+:func:`base64.b64decode` with ``validate=True`` raises now a binascii.Error
+if the input ends with a single ``\n``.