]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-146311: Reject non-canonical padding bits in base32, 64, & 85 decoding (GH-146312)
authorGregory P. Smith <68491+gpshead@users.noreply.github.com>
Sat, 25 Apr 2026 23:02:51 +0000 (16:02 -0700)
committerGitHub <noreply@github.com>
Sat, 25 Apr 2026 23:02:51 +0000 (16:02 -0700)
commitc5fcdb4a9bd04b88f363f0242cbf102a63825c37
tree6e5476d43c7389c076128522712f39677471bbf2
parentb2f126c4a0bad66d4b51028e8754a18e59ad84bb
gh-146311: Reject non-canonical padding bits in base32, 64, & 85 decoding (GH-146312)

Add `canonical=False` keyword argument to `a2b_base64`, `a2b_base32`, `a2b_base85`, and `a2b_ascii85` (and their `base64` module wrappers). When `canonical=True`, non-canonical encodings are rejected per [RFC 4648 section 3.5](https://datatracker.ietf.org/doc/html/rfc4648.html#section-3.5).

This is independent of `strict_mode`.

For base85/ascii85, the check also rejects single-character final groups (never produced by a conforming encoder) and verifies partial group padding matches what the encoder would produce.

Co-authored-by: Serhiy Storchaka via lots of great code review!
12 files changed:
Doc/library/base64.rst
Doc/library/binascii.rst
Doc/whatsnew/3.15.rst
Include/internal/pycore_global_objects_fini_generated.h
Include/internal/pycore_global_strings.h
Include/internal/pycore_runtime_init_generated.h
Include/internal/pycore_unicodeobject_generated.h
Lib/base64.py
Lib/test/test_binascii.py
Misc/NEWS.d/next/Library/2026-04-25-11-56-05.gh-issue-146311.iHWO0v.rst [new file with mode: 0644]
Modules/binascii.c
Modules/clinic/binascii.c.h