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

buffer reading position is wrong when reading string data with code points beyond U+007F

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.12.0 Alpha
    • 5.12.0 Alpha
    • MQTT
    • None
    • 6709c0eecb88a325eba0157214e9c42ac6bd85d7

    Description

      In cases of code points that are encoded with two or more octets in UTF-8

      template<>
      QString QMqttConnection::readBufferTyped()
      {
          const quint16 size = readBufferTyped<quint16>();
          return QString::fromUtf8(reinterpret_cast<const char *>(readBuffer(size).constData()), size);
      }
      

      consumes more octets from the buffer than the position tracking in

              case 0x26: { // 3.15.2.2.5 User property
                  ...
                  const QString propertyValue = readBufferTyped<QString>();
                  propertyLength -= propertyValue.length() + 2;
      

      takes care of.

      Possible resolution:

          template<class T>
          T QMqttConnection::readBufferTyped(int *remainingLen = nullptr);
      
        ...
          template<>
          quint16 QMqttConnection::readBufferTyped(int *remainingLen = nullptr)
         {
               const quint16 result =  qFromBigEndian<quint16>(reinterpret_cast<const quint16 *>(readBuffer(2).constData()));
              if (remainingLen)
                  *remainingLen -= 2;
               return result;
          }
      
          ...
           
          template<>
          QString QMqttConnection::readBufferTyped(int *remainingLen = nullptr)
          {
              const quint16 size = readBufferTyped<quint16>(remainingLen);
              const QByteArray ba = reinterpret_cast<const char *>(readBuffer(size).constData()), size);
              if (remainingLen)
                  *remainingLen -= ba.size();
              return QString::fromUtf8(ba, size);
          }
      

      Attachments

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

        Activity

          People

            mkalinow Maurice Kalinowski
            hjk hjk
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes