Repository navigation
Reject sign and non-ASCII digits in \u escapes - #890
Open
xubenqiang wants to merge 1 commit into
Open
xubenqiang wants to merge 1 commit into
xubenqiang wants to merge 1 commit into
Conversation
A JSON \u escape is exactly four hex digits, but the tokenizer read them with Integer.parseInt(digits, 16), which also accepts a leading sign and any Unicode decimal digit: "\u+041" and "\u0041" parsed as "A", and "\u-041" escaped as an IllegalArgumentException instead of a ConfigException.Parse. Check the four characters are ASCII hex digits before parsing.
Collaborator
|
Hi @xubenqiang, Thank you for your contribution! We really value the time you've taken to put this together. Before we proceed with reviewing this pull request, please sign the Akka Contributors License Agreement: |
Contributor
|
I'd like to point out here that this should consider that the |
This branch has not been deployed
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.
The bug
HOCON.md says quoted strings use JSON escaping, so a
\uescape must be exactly four hex digits.Tokenizerread the four characters and passed them toInteger.parseInt(digits, 16), which also accepts a leading sign and any Unicode decimal digit:a = "\u0041"{a=A}{a=A}a = "\u+041"{a=A}ConfigException.Parse: Malformed hex digitsa = "\u-041"IllegalArgumentException: Not a valid Unicode code pointConfigException.Parse: Malformed hex digitsa = "\u0041"(fullwidth){a=A}ConfigException.Parse: Malformed hex digitsa = "\u٠٠٤١"(Arabic-Indic){a=A}ConfigException.Parse: Malformed hex digitsa = "\u 041",a = "\u004"ConfigException.ParseThe fix checks that each of the four characters is an ASCII hex digit before parsing, so all malformed escapes take the existing
Malformed hex digitspath instead of being accepted or escaping as a bareIllegalArgumentException.Tests
config/src/test/java/com/typesafe/config/impl/UnicodeEscapeParsingTest.javacovers the sign, the two non-ASCII digit forms and the valid escape.Verified locally by compiling
config/src/main/javawith JDK 21 and running the test class with JUnit 4.13.2: OK (2 tests). With theTokenizerchange reverted the test fails withexpected a parse error for a = "\u+041".Note: this repository asks contributors to accept the Typesafe CLA before a pull request can be accepted; I have not signed it.
Refs #884