Skip to content

Commit ec69312

Browse files
luci1900davidism
authored andcommitted
Replace base64 decoding errors with BadData.
1 parent f1ecd77 commit ec69312

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

itsdangerous.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,12 @@ def base64_decode(string):
207207
The result is also a bytestring.
208208
"""
209209
string = want_bytes(string, encoding='ascii', errors='ignore')
210-
return base64.urlsafe_b64decode(string + b'=' * (-len(string) % 4))
210+
string += b'=' * (-len(string) % 4)
211+
212+
try:
213+
return base64.urlsafe_b64decode(string)
214+
except (TypeError, ValueError):
215+
raise BadData('Invalid base64-encoded data')
211216

212217

213218
_int64_struct = struct.Struct('>Q')

0 commit comments

Comments
 (0)