Skip to content

Reject malformed Base64 padding in bytes loaders - #456

Open
gaoflow wants to merge 2 commits into
reagento:developfrom
gaoflow:fix-strict-base64-loading
Open

Reject malformed Base64 padding in bytes loaders#456
gaoflow wants to merge 2 commits into
reagento:developfrom
gaoflow:fix-strict-base64-loading

Conversation

@gaoflow

@gaoflow gaoflow commented Jul 16, 2026

Copy link
Copy Markdown

Problem

The bytes-like loaders pre-check their input against the Base64 alphabet, but binascii.a2b_base64 is permissive about padding. Inputs made only of padding or carrying excess padding, such as =, AAA==, and AAAA=, are therefore accepted and silently decoded. Non-ASCII strings also leak UnicodeEncodeError instead of the loader error contract.

Fix

Validate that padding does not exceed the amount implied by the data length before decoding, while preserving the existing decoder errors for missing padding. Convert non-ASCII input to ValueLoadError consistently.

The shared bytes loader covers bytes, bytearray, BytesIO, and IO[bytes]. Regression coverage exercises all four through Retort across strict/lax coercion and every debug-trail mode, including empty and correctly padded boundary cases.

Validation

  • Python 3.10 targeted matrix: 24 passed
  • Python 3.14 targeted matrix: 24 passed
  • Python 3.14 full suite: 2309 passed, 21 skipped
  • ruff, mypy, typos, custom AST lint, and all pre-commit hooks passed

@gaoflow

gaoflow commented Jul 16, 2026

Copy link
Copy Markdown
Author

The Coverage job failed before reading any coverage data: its first request, GET https://api.github.com/repos/reagento/adaptix, returned HTTP 503 with GitHub's Unicorn HTML page. All seven test jobs that produced the coverage artifacts passed. I attempted to rerun only the failed job, but fork contributors do not have the required repository permission.

@sonarqubecloud

Copy link
Copy Markdown

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