Repository navigation
fix overflow in the integer to floating point safe-cast checks - #1238
Open
aysha-afrah26 wants to merge 1 commit into
Open
aysha-afrah26 wants to merge 1 commit into
aysha-afrah26 wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
The integer to floating point branches of the two safe-cast helpers hit undefined behavior at the 64-bit extremes, the opposite direction from the float to integer boundary fixed in #1162.
checkTruncation(convert_impl.hpp), behindAny::cast<double>, computesstd::abs(static_cast<int64_t>(from)), which overflows forINT64_MIN, so a Debug or UBSan build letsINT64_MINthrough the 2^53 precision check while an -O2 build rejects it.ValidCast(safe_any.hpp), behindBlackboard::seton an entry locked todoubleorfloat, rounds the integer to the floating type and casts it back, butINT64_MAXandUINT64_MAXround up to 2^63 and 2^64, so the cast back is out of range. I noticed it with UBSan: restoring{"x": -9223372036854775808}throughImportBlackboardFromJSONand ticking a Script withr := x < 0reports theabsoverflow and the node returns SUCCESS, while a Release build of the same tree throws the "Loss of precision" error. The fix computes the magnitude in unsigned arithmetic, and inValidCastreturns false when the rounded value is at or above 2^digits of the source type, before casting back, so both extremes are rejected the same way in every build. The newBasicTypes.IntToDoubleBoundarytest fails under the repo's UBSan configuration before the change and passes after (full ctest 539/539 with UBSan); the change is header-inline with no API or ABI impact.