Repository navigation
Reject sign characters in Base16 decoding - #79
Merged
ianopolous merged 1 commit intoDec 3, 2026
Merged
Conversation
Base16.decode used Integer.parseInt(pair, 16), which accepts a leading
'+' or '-'. As a result Multibase.decode("f-1") returned 0xFF and
"f+a" returned 0x0a, silently accepting characters outside the Base16
alphabet (0-9a-f). Decode each hex nibble directly and throw
IllegalArgumentException on any non-hex character.
Member
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Base16.decodedecodes each two-character pair withInteger.parseInt(pair, 16).Integer.parseIntaccepts a leading+or-, so pairs containing a sign are parsed as numbers instead of being rejected, even though+and-are not part of the Base16 alphabet (0-9a-f).Before this change:
This is inconsistent with the existing behaviour for other invalid characters (e.g.
f0gcorrectly throws) and with the multibase spec, whose base16 alphabet is0123456789abcdef.Fix
Decode each hex nibble directly and throw
IllegalArgumentExceptionon any character outside0-9,a-f,A-F. Valid input (including upper-case, as previously accepted byparseInt) is unchanged.Test
Added
f-1andf+atoMultibaseBadInputsTest. Both fail before the fix (decode returns a value) and pass after (decode throws). Full suite is green (123 tests) andspotless:checkpasses.