In the doc of b64decode:
It is claimed that an Exception will be raised if input byte s is incorrectly padded. However, with the argument validate set to False, which is the default value, python check if s is wrongly padded when some padding is missing, but don't check if padding is redundant.
import base64
print(base64.b64decode('aGVsbG8gd29ybGQ=')) # hello world
print(base64.b64decode('aGVsbG8gd29ybGQ======')) # hello world
print(base64.b64decode('aGVsbG8gd29ybGQ======', validate=True)) # binascii.Error: Non-base64 digit found
print(base64.b64decode('aGVsbG8gd29ybGQ')) # binascii.Error: Incorrect padding
I think if we could maybe made this clearer here? This doc really confused me when I'm decoding some base64 data that could be wrong (I expect an error will be raised if the padding of the input is wrong). Thanks.
Edit1: I think the program regard the redundant padding char as char after padding which should be discarded in default mode. Humm, I'm not sure should we consider redundant padding char as an Incorrect padding . For now, we treat aGVsbG8gd29ybGQ as an Incorrect padding but not aGVsbG8gd29ybGQ==, while the correct padding is aGVsbG8gd29ybGQ=.
Linked PRs
In the doc of b64decode:
It is claimed that an Exception will be raised if input byte
sis incorrectly padded. However, with the argumentvalidateset toFalse, which is the default value, python check ifsis wrongly padded when some padding is missing, but don't check if padding is redundant.I think if we could maybe made this clearer here? This doc really confused me when I'm decoding some base64 data that could be wrong (I expect an error will be raised if the padding of the input is wrong). Thanks.
Edit1: I think the program regard the redundant padding char as char after padding which should be discarded in default mode. Humm, I'm not sure should we consider redundant padding char as an
Incorrect padding. For now, we treataGVsbG8gd29ybGQas anIncorrect paddingbut notaGVsbG8gd29ybGQ==, while the correct padding isaGVsbG8gd29ybGQ=.Linked PRs
Incorrect paddinginbase64.rstdocuments #139301