Repository navigation
Fix silent wraparound when reading uint64 > INT64_MAX as signed integer in JSON - #132
Open
clockblocker wants to merge 1 commit into
Open
clockblocker wants to merge 1 commit into
clockblocker wants to merge 1 commit into
Conversation
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.
Summary
Fixes a silent integer wraparound bug in
rfl::json::Reader::to_basic_typewhen reading JSON integers in(INT64_MAX, UINT64_MAX]into signed integer targets (orrfl::Generic).Root Cause
In
yyjson,yyjson_is_int(val)returnstruefor bothYYJSON_SUBTYPE_SINTandYYJSON_SUBTYPE_UINT, whileyyjson_get_sint(val)returnsval->uni.i64directly without checking the subtype. As a result:rfl::json::read<int64_t>("18446744073709551615")silently succeeded and returned-1(and9223372036854775808returnedINT64_MIN).int32_tandint8_talso silently accepted18446744073709551615as-1because-1passed themin()/max()bounds check added in Reject out-of-range JSON integer values munich-data-engineering/reflect-cpp#746.rfl::json::read<rfl::Generic>("18446744073709551615")matched theint64_talternative and silently producedint64_t(-1).Fix
include/rfl/json/Reader.hpp: Dispatchyyjson_is_uintandyyjson_is_sintseparately in the signed-integral branch ofto_basic_type, checkingyyjson_get_uintagainststatic_cast<uint64_t>(std::numeric_limits<Target>::max())instead of bit-reinterpretingu64asi64.tests/json/test_integers.cpp: Addedtest_signed_overflow_from_large_uint64coveringINT64_MAX + 1,UINT64_MAXintoint64_t/int32_t/int8_t, boundaryINT64_MAX/INT64_MIN, andrfl::Generic.Verification
-std=c++20 -Wall -Wextra -Wpedantic -Wshadow -Wconversion -Werror) oninclude/rfl/json/Reader.hpp: passed.tests/json/test_integers.cppunder-fsanitize=undefined -fno-sanitize-recover=all -Wall -Werror: 3/3 passed.