Skip to content

Comments

Wrap NumberFormatException#3282

Merged
bbakerman merged 2 commits intographql-java:masterfrom
arthurscchan:wrap-number-format-exception
Aug 8, 2023
Merged

Wrap NumberFormatException#3282
bbakerman merged 2 commits intographql-java:masterfrom
arthurscchan:wrap-number-format-exception

Conversation

@arthurscchan
Copy link
Contributor

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>
@bbakerman bbakerman added this to the 2023 October milestone Aug 5, 2023
@bbakerman
Copy link
Member

bbakerman commented Aug 5, 2023

Thanks for reporting and fixing these problems.

I feel like we should have a test for these - eg send in an invalid float and see it handled

I know the fuzzing discovered it - but now that this is a known problem - lets lock in the behavior with fixed test

@arthurscchan
Copy link
Contributor Author

@bbakerman Thanks for the reply. I will try to create and add in a unit testing.

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
@bbakerman bbakerman added this pull request to the merge queue Aug 8, 2023
Merged via the queue into graphql-java:master with commit 0265179 Aug 8, 2023
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