Wrap NumberFormatException#3282
Merged
bbakerman merged 2 commits intographql-java:masterfrom Aug 8, 2023
Merged
Conversation
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
Member
|
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 |
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>
284f9bf to
e4e648a
Compare
bbakerman
approved these changes
Aug 8, 2023
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.
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.