Skip to content

Wrap NumberFormatException#1

Open
arthurscchan wants to merge 2 commits into
masterfrom
wrap-number-format-exception
Open

Wrap NumberFormatException#1
arthurscchan wants to merge 2 commits into
masterfrom
wrap-number-format-exception

Conversation

@arthurscchan

Copy link
Copy Markdown
Owner

This fixes a possible unwrapped NumberFormatException in src/main/java/graphql/parser/UnicodeUtil.java and src/main/java/graphql/parser/GraphqlAntlrToLanguage.java while parsing possibly malformed schema.

There are some places in the parser that require parsing numeric values from string to different numeric class types. When some of the text values contain invalid number representation, NumberFormatException are thrown. For example in Line 672 of GraphqlAntlrToLanguage class, the constructor call to the BigDecimal object will throw a NumberFormatException if the float value text has a long exponent which overflows the variable. This internal NumberFormatException is not wrapped or handled and thrown directly to the user and crashes the program. It is better to capture and handle it or wrap it with a project defined exception and error message.

This PR adds an additional try catch block to capture and wrap the NumberFormatException with the InvalidSyntaxException to indicate there is some invalid syntax in the provided schema.

We found this bug using fuzzing by way of OSS-Fuzz, where we recently integrated graphql-java (google/oss-fuzz#10748). OSS-Fuzz is a free service run by Google for fuzzing important open source software. If you'd like to know more about this then I'm happy to go into detail and also set up things so you can receive emails and detailed reports when bugs are found.

Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
@arthurscchan arthurscchan force-pushed the wrap-number-format-exception branch from 284f9bf to e4e648a Compare August 7, 2023 21:56
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