Skip to content

gh-146311: Reject non-zero padding bits in base64/base32 decoding#146312

Draft
gpshead wants to merge 3 commits intopython:mainfrom
gpshead:gh-146311-nonzero-padding-bits
Draft

gh-146311: Reject non-zero padding bits in base64/base32 decoding#146312
gpshead wants to merge 3 commits intopython:mainfrom
gpshead:gh-146311-nonzero-padding-bits

Conversation

@gpshead
Copy link
Member

@gpshead gpshead commented Mar 22, 2026

Summary

  • a2b_base64: reject non-zero padding bits when strict_mode=True
  • a2b_base32: reject non-zero padding bits unconditionally
  • Fix existing test data that incidentally had non-zero padding bits

Per RFC 4648 section 3.5, decoders MAY reject encodings where pad bits are not zero.

gpshead and others added 2 commits March 22, 2026 15:05
RFC 4648 section 3.5 allows decoders to reject encoded data containing
non-zero pad bits. Both a2b_base64 (strict_mode=True) and a2b_base32
currently silently discard non-zero trailing bits instead of raising
binascii.Error. These tests document the expected behavior.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add leftchar validation after the main decode loop in a2b_base64
(strict_mode only) and a2b_base32 (always). Fix existing test data
that incidentally had non-zero padding bits to use characters with
zero trailing bits while preserving the same decoded output.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@gpshead gpshead force-pushed the gh-146311-nonzero-padding-bits branch from 8451e22 to 0ca2563 Compare March 22, 2026 22:07
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@gpshead
Copy link
Member Author

gpshead commented Mar 22, 2026

discussing if base32 needs strict_mode on the issue. not adding a NEWS entry until that is decided.

@gpshead gpshead self-assigned this Mar 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant