Skip to content

Commit 875a9e1

Browse files
committed
range check in IsLosslessFloat to avoid undefined double->float cast
UBSAN gave in Value.IsLosslessFloat: include/rapidjson/document.h:981:38: runtime error: value 3.40282e+38 is outside the range of representable values of type 'float'
1 parent 0d3ee63 commit 875a9e1

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

include/rapidjson/document.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,8 @@ class GenericValue {
978978
bool IsLosslessFloat() const {
979979
if (!IsNumber()) return false;
980980
double a = GetDouble();
981+
if (a < static_cast<double>(-3.4028234e38f) || a > static_cast<double>(3.4028234e38f))
982+
return false;
981983
double b = static_cast<double>(static_cast<float>(a));
982984
return a >= b && a <= b; // Prevent -Wfloat-equal
983985
}

0 commit comments

Comments
 (0)