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

Fix potential undefined beahvior of 5.15 QMap

    XMLWordPrintable

Details

    Description

      For 5.15.x, QMap is mixing quint64 (p) and int (elements in enum) and doing bitwise operation between them, i.e.:
      https://github.com/qt/qtbase/blob/v5.15.16-lts-lgpl/src/corelib/tools/qmap.h#L94C5-L94C77

      And that may lead to undefined behavior when, e.g. ~Black a negative integer, is promoted to quint64 and causes overflow.

      A reproducer is attached, and it is said that the undefined behavior sanitizer that comes with Clang 12 can capture it with such output:

      Qt-5/include/QtCore/qmap.h:94:68: runtime error: implicit conversion from type 'int' of value -2 (32-bit, signed) to type 'unsigned long long' changed the value to 18446744073709551614 (64-bit, unsigned)
      Qt-5/include/QtCore/qmap.h:95:80: runtime error: implicit conversion from type 'int' of value -4 (32-bit, signed) to type 'unsigned long long' changed the value to 18446744073709551612 (64-bit, unsigned)
      

      Notice that it can be compiler specific. My gcc 11.4 UBSAN does not detect anything. Older Clang may not detect anything either.

      A patch is also uploaded. We may consider merge it, or at least verify if it's valid.

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            luqiaochen Luqiao Chen
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes