Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Avoid integer overflow UB in basic_json_parser #542

Merged
merged 1 commit into from
Oct 7, 2024

Conversation

PragmaTwice
Copy link
Contributor

In Kvrocks we faced an integer overflow detected by UBSAN in basic_json_parser.

/home/runner/work/kvrocks/kvrocks/build/_deps/jsoncons-src/include/jsoncons/json_parser.hpp:180:74: runtime error: signed integer overflow: 2147483647 + 2 cannot be represented in type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /home/runner/work/kvrocks/kvrocks/build/_deps/jsoncons-src/include/jsoncons/json_parser.hpp:180:74 in 

The reason is that we set max_nesting_depth to numeric_limits::max(), so that max_nesting_depth + 2 leads to overflow.

Here I use an equivalent form to eliminate the problem.

@danielaparker danielaparker merged commit a500279 into danielaparker:master Oct 7, 2024
57 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants