[SERVER-68339] Spurious UBSAN failure when casting large double to float in column store index encoder Created: 26/Jul/22  Updated: 12/Jan/23

Status: Open
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Charlie Swanson Assignee: Backlog - Query Execution
Resolution: Unresolved Votes: 0
Labels: pm2646-m5
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Execution
Operating System: ALL
Sprint: QE 2022-09-19, QE 2022-10-03, QE 2022-10-31, QE 2022-11-14, QE 2022-11-28, QE 2022-12-12, QE 2022-12-26, QE 2023-01-09
Participants:

 Description   

It looks like we need to check whether a double is within float's numeric limits before casting to a float to see if we lose precision here: https://github.com/mongodb/mongo/blob/044d2f734e0dba40b9dfb02cc49c2bff8f575cd5/src/mongo/db/index/column_cell.cpp#L86



 Comments   
Comment by Charlie Swanson [ 22/Nov/22 ]

Throwing back on the QE backlog for the project as I move onto another project.

Comment by Mathias Stearn [ 27/Jul/22 ]

This isn't actually UB. It is a bug in UBSAN that was fixed at some point between clang-8 and clang-9: https://godbolt.org/z/d8Yrq6e4W. Clang documents that this should not produce an error:

-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.

Rather than modifying the code, I'd suggest passing -fno-sanitize=float-cast-overflow when using UBSAN until we upgrade to the v4 toolchain.

Generated at Thu Feb 08 06:10:32 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.