Skip to content

Commit 4308149

Browse files
Fix UBSan float-cast-overflow in BridgingTest.numberTest
Summary: The third assertion in `BridgingTest.numberTest` cast a `double` value of `4294967254.0` (the round-tripped representation of `(uint32_t)-42` through JSI) directly to `int32_t`. Float-to-int conversion is undefined behavior when the value is outside the destination type's range, which UBSan catches on Linux. macOS and Windows builds (without UBSan) silently produced some int value that happened to be != -42, satisfying the `EXPECT_FALSE`. The remaining two assertions already validate the meaningful round-trip property — that `(uint32_t)-42` survives a trip through JSI and decodes correctly when read back as `uint32_t`. The deleted `EXPECT_FALSE` was effectively documenting "don't cast directly to int32, it's UB" via UB itself, which is not a useful test. Changelog: [Internal] - Remove UB-relying assertion from BridgingTest.numberTest UndefinedBehaviorSanitizer: float-cast-overflow xplat/js/react-native-github/packages/react-native/ReactCommon/react/bridging/tests/BridgingTest.cpp:73:3 Test was never completed. The test process might have crashed. Buck UI: https://www.internalfb.com/buck2/0e81623b-a566-4181-a630-633a9b0144f5 Test UI: https://www.internalfb.com/intern/testinfra/testrun/22236523178966589 Network: Up: 18KiB Down: 19KiB (reSessionID-47fd7d68-411c-4457-bd30-9da43be7bd6e) Loading targets. Remaining 0/71 1705 dirs read, 2636 targets declared Analyzing targets. Remaining 0/699 23626 actions, 35339 artifacts declared Executing actions. Remaining 0/4161 37:55.2s exec time total Command: test. Finished 1 local, 1256 cache (99% hit) 37:49.9s exec time cached (99%) Time elapsed: 8.6s Buck UI: https://www.internalfb.com/buck2/0e81623b-a566-4181-a630-633a9b0144f5 Tests finished: Pass 23. Fail 1. Timeout 0. Fatal 0. Skip 0. Omit 0. Infra Failure 0. Build failure 0 1 TESTS FAILED ✗ fbsource//xplat/js/react-native-github/packages/react-native/ReactCommon/react/bridging:tests - BridgingTest.numberTest Run $ fdb buck test <args> to debug fbsource//xplat/js/react-native-github/packages/react-native/ReactCommon/react/bridging:tests - BridgingTest.numberTest ^^^ just prefix your previous command! ($ fdb !!) Learn more at https://fburl.com/fdb Use Devmate to fix your errors. Just click the following link: fb-vscode://nuclide.code-compose/devmate/fixtests?run_id=22236523178966589&expiry=2026-05-05T23%3A25%3A46Z&viewer=635101758&signature=43cbc805019cc8a73bade59398f40cf642acd0f57d8fb3377839888ccf52d5d85d5c63d9d0c39ea9956d9aefc641fda19c87c6cdba6136b5a3dd5a67c42cdb92dc4721930a [chpurrer@166047.od /data/sandcastle/boxes/fbsource (b6d9fba9d4)]$ ``` Differential Revision: D103954447
1 parent c33582b commit 4308149

1 file changed

Lines changed: 0 additions & 5 deletions

File tree

packages/react-native/ReactCommon/react/bridging/tests/BridgingTest.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,6 @@ TEST_F(BridgingTest, numberTest) {
6969
-42,
7070
static_cast<uint32_t>(
7171
bridging::toJs(rt, static_cast<uint32_t>(-42)).asNumber()));
72-
73-
EXPECT_FALSE(
74-
-42 ==
75-
static_cast<int32_t>(
76-
bridging::toJs(rt, static_cast<uint32_t>(-42)).asNumber()));
7772
}
7873

7974
TEST_F(BridgingTest, stringTest) {

0 commit comments

Comments
 (0)