You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The above b32decode call should raise an incorrect padding error.
binascii.a2b_base32 doesn't reset its pads counter after a data character. Ignored earlier '=' characters are counted towards the final padding check.
esoteric. hit in practice? i'd hope not. who would actually use = as padding? but b64decode handles this error case, b32 should as well. a fix is likely just:
--- a/Modules/binascii.c+++ b/Modules/binascii.c@@ -1773,6 +1773,7 @@
}
goto error;
}
+ pads = 0;
switch (octa_pos) {
case 0:
--- a/Lib/test/test_binascii.py+++ b/Lib/test/test_binascii.py@@ -1255,6 +1255,14 @@
eq(a2b_base32(b'MFRGGZD=F', ignorechars=b'='), b'abcde')
eq(a2b_base32(b'MFRGGZDF=', ignorechars=b'='), b'abcde')
eq(a2b_base32(b'MFRA======', ignorechars=b'='), b'ab')
+ # 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'=')
eq(a2b_base32(b'A1B3C5W7Z9', ignorechars=b'19WZ'), b'\x00v.\xdb\xf9')
eq(a2b_base32(b'A1B3C5W7Z9', ignorechars=b'19WZ',
Activity
omkar-334 commentedon Nov 21, 2026
hey @gpshead id like to work on this