Skip to content

Decode base64Binary strictly in value holders and the rich parser - #131

Merged
pjfanning merged 1 commit into
apache:trunkfrom
pjfanning:base64-strict
Oct 4, 2026
Merged

pjfanning merged 1 commit into
apache:trunkfrom
pjfanning:base64-strict

Conversation

@pjfanning

Copy link
Copy Markdown
Member

Follow-up to #123.

#123 rejected non-alphabet characters in JavaBase64Holder.lex, but two gaps remained:

  • XMLStreamReaderExtImpl.getBase64Value / getAttributeBase64Value (both overloads) still decoded with Base64.getMimeDecoder(), so SGVsbG8=!!!! came back as Hello.
  • The JDK decoders treat padding as optional, so unpadded or wrongly sized values such as SGVsbG8 and SGVsbG still validated, although the base64Binary lexical space requires 4-char groups with = padding only at the end.

This adds org.apache.xmlbeans.impl.util.Base64Bin.decode (a sibling of HexBin; it returns null for invalid input). It strips XML whitespace, requires length % 4 == 0, then uses the basic Base64 decoder, which rejects non-alphabet chars and misplaced padding. The holder and all three rich parser getters use it.

Not enforced: XSD 1.0's restriction on the final char before padding (non-zero trailing bits, e.g. SGW=). The JDK accepts these, and rejecting them looked more likely to break real documents than to catch anything.

Tests: new Base64BinTest; Base64BinaryValidateTest gains padding/length cases and compiles the schema once; RichParserTests covers the stray-char and unpadded cases on element and attribute getters.

🤖 Generated with Claude Code

Add Base64Bin.decode, which ignores XML whitespace and otherwise requires
the base64 alphabet in groups of four with padding only at the end.
JavaBase64Holder.lex and the XMLStreamReaderExtImpl base64 getters now
use it instead of the JDK MIME decoder, which drops non-alphabet chars
and accepts unpadded input.

Follow-up to apache#123: the rich parser getters still accepted stray chars,
and unpadded or wrongly sized values (e.g. "SGVsbG8") still validated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pjfanning
pjfanning merged commit ab4639a into apache:trunk Oct 4, 2026
3 checks passed
@pjfanning
pjfanning deleted the base64-strict branch October 4, 2026 16:09
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