Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Lib/base64.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@


bytes_types = (bytes, bytearray) # Types acceptable as binary data
_has_non_base16_digits = re.compile(b'[^0-9A-F]').search

def _bytes_from_decode_data(s):
if isinstance(s, str):
Expand Down Expand Up @@ -263,7 +264,7 @@ def b16decode(s, casefold=False):
s = _bytes_from_decode_data(s)
if casefold:
s = s.upper()
if re.search(b'[^0-9A-F]', s):
if _has_non_base16_digits(s):
raise binascii.Error('Non-base16 digit found')
return binascii.unhexlify(s)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Use compiled regex in :func:`base64.b16decode` for validation.
Patch by Karthikeyan Singaravelan.