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

Integer overflow in qt_gettime for Mac OS X (may lead to CPU hogging on PowerPC)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Incomplete
    • Icon: Not Evaluated Not Evaluated
    • None
    • 4.7.2, 4.7.3, 4.8.0
    • Core: Date/Time
    • None
    • Discovered on Mac OS X 10.5 on a PowerPC.
    • macOS

      corelib/tools/qelapsedtimer_mac.cpp, static qint64 absoluteToNSecs(qint64 cpuTime)

      Integer overflow in line:

      qint64 nsecs = cpuTime * info.numer / info.denom;

      On PowerPC Macs, info.numer can be 1,000,000,000. Multiplying this by cpuTime can overflow the maximum value of qint64, leading to all sorts of wacky results. Suggested fix:

      qint64 nsecs = cpuTime * ( (double)info.numer / (double)info.denom );

      (As an aside, wherever absoluteToNSecs() or absoluteToMSecs() are called it is smashing an unsigned integer into a signed integer. But I haven't found that to be problematic.)

      Worst case scenario: on a QThread that has a QTimer with a 5 second repeating timeout, this integer overflow may cause QTimerInfoList::timerWait to calculate a timeval that is too big for system ::select() to handle, which causes ::select to return EINVAL, which forces the event loop into a cpu-hogging cycle.

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

            Unassigned Unassigned
            branewave Paul Sturm
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes