Fix signed integer overflow#465
Open
MichaelChirico wants to merge 4 commits into
Open
Conversation
Check for overflow before multiplying and adding/subtracting digits.
522f669 to
5b93275
Compare
Contributor
Author
|
We could also use https://clang.llvm.org/docs/LanguageExtensions.html#checked-arithmetic-builtins |
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 was an error produced by a fuzzer we set up for
yajl, fixed by Gemini, and ported to this bundled version by Gemini.yajl_parse_integerwas susceptible to signed integer overflow when parsing numbers close to or exceedingLLONG_MAX/LLONG_MINlimits. It performed multiplication and addition before checking if the result would overflow.Solution:
Refactor the parsing loop in
yajl_parse_integerto check for potential overflow before modifying the accumulator:LLONG_MAX.LLONG_MINwhich has larger absolute value thanLLONG_MAX) and check if multiplying by 10 or subtracting the next digit would exceedLLONG_MIN.errnotoERANGEand return the capped value (LLONG_MAX/LLONG_MIN) upon overflow, allowing the YAJL tree parser to fall back to double precision representation.