Skip to content

Reject invalid Base64 padding in Bytes decoding - #2891

Open
haoshengzhen wants to merge 1 commit into
o1-labs:mainfrom
haoshengzhen:fix-base64-padding-validation
Open

Reject invalid Base64 padding in Bytes decoding#2891
haoshengzhen wants to merge 1 commit into
o1-labs:mainfrom
haoshengzhen:fix-base64-padding-validation

Conversation

@haoshengzhen

Copy link
Copy Markdown

Summary

This PR makes Bytes.base64Decode() reject Base64 inputs that contain = padding before the end of the input.

Previously, base64DecodeLookup() accepted = as a valid character anywhere in the input, while the base64Decode() docs warned that padding in the middle could cause unexpected decoding results. The decoder now enforces that padding can only appear in the final two positions and that padding is contiguous once it starts.

Changes

  • Add Base64 padding validation before decoding.
  • Add a unit test for padding before the end of the input.
  • Update the changelog under Unreleased / Fixed.

Verification

  • npm run format:check -- CHANGELOG.md src/lib/provable/bytes.ts src/lib/provable/test/base64.unit-test.ts
  • npx prettier --config .prettierrc.md.cjs --check CHANGELOG.md
  • git diff --check

Signed-off-by: haoshengzhen <haoshengzhen@outlook.com>
@haoshengzhen

Copy link
Copy Markdown
Author

@martyall @Trivo25 Hi, Could you please review this PR at your convenience? Thank you very much.

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