[SERVER-50662] Support large doubles and other double values in FTDC Created: 31/Aug/20  Updated: 29/Oct/23  Resolved: 30/Sep/20

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 4.4.7, 5.0.0-rc0

Type: Bug Priority: Major - P3
Reporter: Mark Benvenuto Assignee: Mark Benvenuto
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v5.0, v4.4
Sprint: Security 2020-10-05
Participants:
Linked BF Score: 56

 Description   

FTDC converts doubles to int64. This leads to undefined behavior if the double is -inf, +inf or does not fit in [INT64_MIN, INT64_MAX].

This was detected by clang's ubsan sanitizer

-fsanitize=float-cast-overflow: Conversion to, from, or between floating-point types which would overflow the destination. Because the range of representable values for all floating-point types supported by Clang is [-inf, +inf], the only cases detected are conversions from floating point to integer types.

References:
https://github.com/llvm/llvm-project/blob/42170b3b4e1f7d30b377a3da07c354feae9b852e/compiler-rt/lib/ubsan/ubsan_handlers.cpp#L481-L520
https://github.com/llvm/llvm-project/blob/646f19bb9dc86ea5baf38969697a15d0f162ddb0/clang/lib/CodeGen/CGExprScalar.cpp#L897-L963



 Comments   
Comment by Githook User [ 11/Jun/21 ]

Author:

{'name': 'Mark Benvenuto', 'email': 'mark.benvenuto@mongodb.com', 'username': 'markbenvenuto'}

Message: SERVER-50662 Handle large and non-finite doubles in FTDC

(cherry picked from commit d47784296374ed335d07c895820fdf8066e538e3)
Branch: v4.4
https://github.com/mongodb/mongo/commit/f647417228cb45bf1866f1b2f437f34c619d84b6

Comment by Githook User [ 29/Sep/20 ]

Author:

{'name': 'Mark Benvenuto', 'email': 'mark.benvenuto@mongodb.com', 'username': 'markbenvenuto'}

Message: SERVER-50662 Handle large and non-finite doubles in FTDC
Branch: master
https://github.com/mongodb/mongo/commit/d47784296374ed335d07c895820fdf8066e538e3

Comment by Bruce Lucas (Inactive) [ 02/Sep/20 ]

That seems reasonable.

Comment by Mark Benvenuto [ 01/Sep/20 ]

I have to define how FTDC will translate these double values that cannot be represented as int64. It will be a lossy transformation. I mostly see these large values as an error so I am okay with losing information.

Here is an example of the transformation I am considering.

double int64
inf MAX_INT64
>MAX_INT64 MAX_INT64
-inf MIN_INT64
<MIN_INT64 MIN_INT64
Comment by Bruce Lucas (Inactive) [ 01/Sep/20 ]

What did you have in mind by "support"? If you mean encode those values losslessly in FTDC, I'm dubious of the value, considering the impact in churn, complexity, and cost that would have for consumers. If you just mean encode them as 64-bit ints in a well-defined way, that seems reasonable.

Generated at Thu Feb 08 05:23:14 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.