From ec69312709b42add477a6c00131c3d2155b2fe23 Mon Sep 17 00:00:00 2001 From: Lucian Branescu Mihaila Date: Tue, 13 Aug 2013 11:42:23 +0100 Subject: [PATCH] Replace base64 decoding errors with BadData. --- itsdangerous.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/itsdangerous.py b/itsdangerous.py index e407627..5e53a32 100644 --- a/itsdangerous.py +++ b/itsdangerous.py @@ -207,7 +207,12 @@ def base64_decode(string): The result is also a bytestring. """ string = want_bytes(string, encoding='ascii', errors='ignore') - return base64.urlsafe_b64decode(string + b'=' * (-len(string) % 4)) + string += b'=' * (-len(string) % 4) + + try: + return base64.urlsafe_b64decode(string) + except (TypeError, ValueError): + raise BadData('Invalid base64-encoded data') _int64_struct = struct.Struct('>Q')