Skip to content

Translate base64 name-decode errors to StreamReadException#882

Open
Sahana2524 wants to merge 2 commits into
FasterXML:3.xfrom
Sahana2524:base64-name-decode-error
Open

Translate base64 name-decode errors to StreamReadException#882
Sahana2524 wants to merge 2 commits into
FasterXML:3.xfrom
Sahana2524:base64-name-decode-error

Conversation

@Sahana2524

@Sahana2524 Sahana2524 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

When a base64 XmlNameProcessor is configured, reading a name that is not valid base64 lets the decoder's exception escape the parser:

java.lang.IllegalArgumentException: Input byte[] should at least have 2 bytes for base64 bytes
    at java.base/java.util.Base64$Decoder.decode(...)
    at ...XmlNameProcessors$AlwaysOnBase64NameProcessor.decodeName(XmlNameProcessors.java:230)
    at ...deser.XmlTokenStream._decodeElementName(XmlTokenStream.java:786)
    at ...deser.FromXmlParser._nextToken(FromXmlParser.java:1421)

The base64 processors decode every incoming element/attribute name through java.util.Base64, which throws IllegalArgumentException on malformed input. That went uncaught, so callers guarding reads with catch (JacksonException) see a raw runtime exception instead.

The base64 processors in XmlNameProcessors now translate the decoder's IllegalArgumentException into a StreamReadException at the point of decode, so the failure is handled where it happens and cannot leak through any parser path (root-name decode in XmlTokenStream.initialize() or later names in _nextToken()). Valid names and the default passthrough processor are unchanged. Added regression tests in XmlNameEscapeTest for both the prefixed and always-on base64 processors.

@github-actions

Copy link
Copy Markdown

🧪 Code Coverage Report

Metric Coverage Change
Instructions coverage 73.56% 📈 +0.030%
Branches branches 68.03% 📈 +0.000%

Coverage data generated from JaCoCo test results

@cowtowncoder

Copy link
Copy Markdown
Member

Test makes sense and problem should be addressed. But not in "nextToken()" calls -- needs to be closer to the actual fail, NameProcessor must translate failures and not leak them through.

@Sahana2524

Copy link
Copy Markdown
Contributor Author

Makes sense. Moved the translation into the base64 processors themselves: decodeName now wraps the decoder's IllegalArgumentException in a StreamReadException, and the parser-side catches are reverted. That covers both the root-name path and _nextToken() from the same place. Tests unchanged, full suite still passes.

@github-actions

Copy link
Copy Markdown

🧪 Code Coverage Report

Metric Coverage Change
Instructions coverage 73.59% 📈 +0.040%
Branches branches 68.08% 📈 +0.000%

Coverage data generated from JaCoCo test results

@cowtowncoder cowtowncoder changed the title translate base64 name-decode errors to StreamReadException Translate base64 name-decode errors to StreamReadException Jul 23, 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.

2 participants