Closed Bug 1772646 Opened 4 years ago Closed 4 years ago

gfx/layers/apz/test/gtest/APZTestCommon.h:54:10: runtime error: -172.371 is outside the range of representable values of type 'unsigned int'

Categories

(Core :: Panning and Zooming, defect)

defect

Tracking

()

RESOLVED FIXED
103 Branch
Tracking Status
firefox103 --- fixed

People

(Reporter: tsmith, Assigned: botond)

References

(Blocks 1 open bug)

Details

(Keywords: csectype-undefined)

Attachments

(1 external file)

This was found by enabling the float-cast-overflow check in UBSan and running existing tests. This type of issue can create inconsistencies across platforms, architectures and optimization levels.

Found with m-c 20220603-68727ef04ccf

To enable this check add the following to your mozconfig:

ac_add_options --enable-undefined-sanitizer="float-cast-overflow"

This issue is found by the existing test: APZCTreeManagerGenericTesterMock.Bug1194876

TEST-START | APZCTreeManagerGenericTesterMock.Bug1194876
/builds/worker/checkouts/gecko/gfx/layers/apz/test/gtest/APZTestCommon.h:54:10: runtime error: -172.371 is outside the range of representable values of type 'unsigned int'
    #0 0x7fe4a19d23f0 in MillisecondsSinceStartup /builds/worker/checkouts/gecko/gfx/layers/apz/test/gtest/APZTestCommon.h:54:10
    #1 0x7fe4a19d23f0 in CreateMultiTouchInput /builds/worker/checkouts/gecko/gfx/layers/apz/test/gtest/InputUtils.h:46:33
    #2 0x7fe4a19d23f0 in APZCTreeManagerGenericTesterMock_Bug1194876_Test::TestBody() /builds/worker/checkouts/gecko/gfx/layers/apz/test/gtest/TestTreeManager.cpp:127:9
    #3 0x7fe4a17b9259 in testing::Test::Run() /builds/worker/checkouts/gecko/third_party/googletest/googletest/src/gtest.cc:2670:5
    #4 0x7fe4a17bb02a in testing::TestInfo::Run() /builds/worker/checkouts/gecko/third_party/googletest/googletest/src/gtest.cc:2849:11
    #5 0x7fe4a17bcfd7 in testing::TestSuite::Run() /builds/worker/checkouts/gecko/third_party/googletest/googletest/src/gtest.cc:3008:30
    #6 0x7fe4a17dbb27 in testing::internal::UnitTestImpl::RunAllTests() /builds/worker/checkouts/gecko/third_party/googletest/googletest/src/gtest.cc:5866:44
    #7 0x7fe4a17daabd in testing::UnitTest::Run() /builds/worker/checkouts/gecko/third_party/googletest/googletest/src/gtest.cc:5440:10
    #8 RUN_ALL_TESTS /builds/worker/workspace/obj-build/dist/include/gtest/gtest.h:2286:73
    #9 0x7fe4a1771a50 in mozilla::RunGTestFunc(int*, char**) /builds/worker/checkouts/gecko/testing/gtest/mozilla/GTestRunner.cpp:156:10
    #10 0x7fe4b01f1033 in XREMain::XRE_mainStartup(bool*) /builds/worker/checkouts/gecko/toolkit/xre/nsAppRunner.cpp:4760:16
    #11 0x7fe4b01febeb in XREMain::XRE_main(int, char**, mozilla::BootstrapConfig const&) /builds/worker/checkouts/gecko/toolkit/xre/nsAppRunner.cpp:5915:12
    #12 0x7fe4b01ffa3b in XRE_main(int, char**, mozilla::BootstrapConfig const&) /builds/worker/checkouts/gecko/toolkit/xre/nsAppRunner.cpp:5991:21
    #13 0x559c181a2a39 in do_main(int, char**, char**) /builds/worker/checkouts/gecko/browser/app/nsBrowserApp.cpp:227:22
    #14 0x559c181a1cae in main /builds/worker/checkouts/gecko/browser/app/nsBrowserApp.cpp:406:16
    #15 __libc_start_main /tmp/glibc/csu/../csu/libc-start.c:310
    #16 0x559c180e1c80 in _start (/builds/worker/workspace/build/application/firefox/firefox+0x72c80) (BuildId: 42cda71a61972be2e9518daa796551945b598f1e)

This issue is currently triggered while running existing tests with the 'float-cast-overflow' UBSan check enabled. This issue will need to be addressed before the check can be enabled by default.

If it requires too much effort to fix immediately please ni? me and let me know. If necessary it will be added to a suppression list. Thank you :)

Flags: needinfo?(botond)
Assignee: nobody → botond
Flags: needinfo?(botond)

MillisecondsSinceStartup() is subtracting GetStartupTime() from an input timestamp, and the issue is the result is sometimes negative (in which case UBSan complains about converting it to an unsigned integer).

GetStartupTime() is implemented by initializing a static timestamp on first call, and returning that.

The input timestamps come from the MockContentController's internal timestamp, which is initialized to GetStartupTime() and then only ever moved forward, so the subtraction should never yield a negative result.

So, how do we get a negative result? Debugging reveals that GetStartupTime() appears to initialize its static timestamp twice!

The reason for this is that the function GetStartupTime() is itself static, and it's declared in a header. This means every translation unit which includes the header gets its own copy of the function, and in particular its own copy of the function's static local variable. The first call in each translation unit triggers initialization of the corresponding static local, and subtracting timestamps originating in different translation units can get us into trouble.

If it's static, every translation unit gets its own copy of
the static local variable sStartupTime.

Since it's defined in a header, we make it inline instead.

Pushed by bballo@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/848d45e8ea11 Make GetStartupTime() non-static. r=hiro
Status: NEW → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 103 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: