Skip to content
Open
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
8 changes: 8 additions & 0 deletions Lib/test/test_binascii.py
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,14 @@ def test_base32_ignorechars(self):
eq(a2b_base32(b'A1B3C5W7Z9', ignorechars=b'19WZ'), b'\x00v.\xdb\xf9')
eq(a2b_base32(b'A1B3C5W7Z9', ignorechars=b'19WZ',
alphabet=binascii.BASE32HEX_ALPHABET), b'PV6\x14\xe9')
# Ignored pad characters do not count as trailing padding.
eq(a2b_base32(b'=MF=RA====', ignorechars=b'='), b'ab')

for data in (b'======ME', b'=ME=====', b'M======E', b'ME==FR==',
b'=MFRGG43'):
with self.subTest(data=data):
with self.assertRaisesRegex(binascii.Error, 'Incorrect padding'):
a2b_base32(data, ignorechars=b'=')

def test_base32_alphabet(self):
alphabet = b'0Aa1Bb2Cc3Dd4Ee5Ff6Gg7Hh8Ii9JjKk'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix :func:`binascii.a2b_base32` accepting invalid padding when padding
characters are included in ``ignorechars``.
2 changes: 2 additions & 0 deletions Modules/binascii.c
Original file line number Diff line number Diff line change
Expand Up @@ -1774,6 +1774,8 @@ binascii_a2b_base32_impl(PyObject *module, Py_buffer *data, int padded,
goto error;
}

pads = 0;

switch (octa_pos) {
case 0:
octa_pos = 1;
Expand Down
Loading