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

incorrect time returned from qt_gettime() after integer overflow in qelapsedtimer_mac.cpp -> syslog hogged

    XMLWordPrintable

Details

    • Bug
    • Resolution: Incomplete
    • Not Evaluated
    • None
    • 4.7.4
    • Core: Other
    • None
    • Mac OS X 10.5.8, PPC
    • macOS

    Description

      Hi,

      I have a few Qt applications (e.g. Qt Designer) that, all of a sudden, begin to spam my syslog with zillions of "select: invalid argument" messages. These messages are generated faster than they are written to disk, and syslogd eats all the system memory for buffering, bringing the whole system to crawl.

      The error message is generated in QEventDispatcherUNIXPrivate::doSelect():

      // EINVAL... shouldn't happen, so let's complain to stderr                
      // and hope someone sends us a bug report
      perror("select");
      

      So here is the bug report...

      The man page gives two reasons for EINVAL:

           [EINVAL]           The specified time limit is invalid.  One of its com-
                              ponents is negative or too large.
      
           [EINVAL]           ndfs is greater than FD_SETSIZE and _DARWIN_UNLIM-
                              ITED_SELECT is not defined.
      

      Further investigation shows that:

      • the messages begin after select() was called with a timeout value with tv_sec ~ 1.2e9
      • Darwin select() implementation returns EINVAL if the tv_sec field is >= 1e8

      The root cause seems to be located here (qelapsedtimer_mac.cpp):

      static qint64 absoluteToNSecs(qint64 cpuTime)
      {
          if (info.denom == 0)
              mach_timebase_info(&info);
          qint64 nsecs = cpuTime * info.numer / info.denom;
          return nsecs;
      }
      

      The problem here is that the multiplication can overflow.

      The latest debugging session gave these values right before the first invalid argument message:

      info.numer 1000000000
      info.denom 18431648
      cpu_time 5072980886283
      nsecs 6850500447
      

      This is called from
      QEventDispatcherUNIX::processEvents() -> QTimerInfoList::timerWait() -> QTimerInfoList::updateCurrentTime() -> qt_gettime()

      FWIW, the system in question is a G4 PowerBook with an uptime of 24 days.

      The attached patch uses doubles to work around the overflow.

      Attachments

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

        Activity

          People

            Unassigned Unassigned
            mklein-qt Michael Klein
            Votes:
            2 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes