summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-01-05 04:32:45 -0800
committerGitHub <noreply@github.com>2020-01-05 04:32:45 -0800
commit3bdb2d9daf3ce41b325bd508e3dd29041e85dd1f (patch)
tree4d6b886066c1dd5d9d2e5c2427c8f5e3605dc615
parent880a17af7d063fcef225a46b7f4ae35d792b2f11 (diff)
downloadcpython-git-3bdb2d9daf3ce41b325bd508e3dd29041e85dd1f.tar.gz
bpo-39055: Reject a trailing \n in base64.b64decode() with validate=True. (GH-17616)
(cherry picked from commit b19c0d77e6f25ea831ab608c71f15d0d9266c8c4) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
-rwxr-xr-xLib/base64.py2
-rw-r--r--Lib/test/test_base64.py1
-rw-r--r--Misc/NEWS.d/next/Library/2019-12-15-19-23-23.bpo-39055.FmN3un.rst2
3 files changed, 4 insertions, 1 deletions
diff --git a/Lib/base64.py b/Lib/base64.py
index 2be9c395a9..2e70223dfe 100755
--- a/Lib/base64.py
+++ b/Lib/base64.py
@@ -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)
diff --git a/Lib/test/test_base64.py b/Lib/test/test_base64.py
index 2a4cc2acad..7dba6635d4 100644
--- a/Lib/test/test_base64.py
+++ b/Lib/test/test_base64.py
@@ -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
index 0000000000..83b1431e92
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-12-15-19-23-23.bpo-39055.FmN3un.rst
@@ -0,0 +1,2 @@
+:func:`base64.b64decode` with ``validate=True`` raises now a binascii.Error
+if the input ends with a single ``\n``.