Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-135201

tst_QHeaderView is full of signed overflow (UB)

    XMLWordPrintable

Details

    • 3692f14a3 (dev)

    Description

      Undefined Behaviour Sanitizer is going nuts in tst_QHeaderView::calculateAndCheck() because of all the signed overflows. I've tried to port them to qint64, but a) that still overflows and b) the test then fails, so I guess all those magic numbers are actually based on modulo arithmetic. But signed overflow is UB, not modulo arithmetic.

      git-blame fingers qtbase/f0a8a4293a635614d1f6cea68c438f8f430f1bbc; assigning to author.

      Please port to uint if you need modulo arithmetic.

      Says UBSan:

      ASS   : tst_QHeaderView::sectionsDontSortWhenNotClickingInThem()
      PASS   : tst_QHeaderView::initialSortOrderRole()
      /home/marc/Qt/qtbase-submit/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp:2887:24: runtime error: signed integer overflow: 12535108 * 3133777 cannot be represented in type 'int'
      /home/marc/Qt/qtbase-submit/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp:2892:25: runtime error: signed integer overflow: 12535108 * 3133777 cannot be represented in type 'int'
      /home/marc/Qt/qtbase-submit/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp:2897:23: runtime error: signed integer overflow: 162956404 * 3133777 cannot be represented in type 'int'
      /home/marc/Qt/qtbase-submit/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp:2897:23: runtime error: signed integer overflow: 83190088 * 42 cannot be represented in type 'int'
      /home/marc/Qt/qtbase-submit/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp:2892:25: runtime error: signed integer overflow: -127173652 * 36 cannot be represented in type 'int'
      /home/marc/Qt/qtbase-submit/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp:2887:24: runtime error: signed integer overflow: 119710026 * 49 cannot be represented in type 'int'
      /home/marc/Qt/qtbase-submit/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp:2922:27: runtime error: signed integer overflow: 56407986 * 3133777 cannot be represented in type 'int'
      /home/marc/Qt/qtbase-submit/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp:2924:28: runtime error: signed integer overflow: 56407986 * 3133777 cannot be represented in type 'int'
      /home/marc/Qt/qtbase-submit/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp:2922:27: runtime error: signed integer overflow: -91841271 * 24 cannot be represented in type 'int'
      /home/marc/Qt/qtbase-submit/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp:2924:28: runtime error: signed integer overflow: -91841271 * 24 cannot be represented in type 'int'
      PASS   : tst_QHeaderView::logicalIndexAtTest(no_updates+normal)
      PASS   : tst_QHeaderView::logicalIndexAtTest(hasupdates+normal)
      PASS   : tst_QHeaderView::logicalIndexAtTest(no_updates+special)
      PASS   : tst_QHeaderView::logicalIndexAtTest(hasupdates+special)
      PASS   : tst_QHeaderView::visualIndexAtTest(no_updates+normal)
      PASS   : tst_QHeaderView::visualIndexAtTest(hasupdates+normal)
      PASS   : tst_QHeaderView::visualIndexAtTest(no_updates+special)
      PASS   : tst_QHeaderView::visualIndexAtTest(hasupdates+special)
      /home/marc/Qt/qtbase-submit/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp:2904:61: runtime error: signed integer overflow: 702 * 3133777 cannot be represented in type 'int'
      /home/marc/Qt/qtbase-submit/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp:2904:29: runtime error: signed integer overflow: 56812498 + 2130464690 cannot be represented in type 'int'
      PASS   : tst_QHeaderView::hideShowTest(no_updates+normal)
      

      Line numbers are as at https://codereview.qt-project.org/c/qt/qtbase/+/634732/1

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            tmartsum Thorbjørn Lund Martsum
            mmutz Marc Mutz
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes