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

Cannot safely validate complex DBus structures in a variant map

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.15.2
    • Core: Other
    • None

    Description

      When passing a complex type inside a variant map, I can't safely validate and cast the value.

      Imagine getting pixmap data sent as a struct, like (iiiay) (width, height, rowstride, byte array) inside of a variant map a(sv), like is done in freedesktop Notification spec. I can't check whether the type I get matches the expected signature and doing a qdbus_cast might trigger an assert in libdbus should the client sends bogus data.

      DBus setup:

      struct MyImage {
          int width, height, rowStride;
          QByteArray data;
      };
      
      QDBusArgument &operator<< (QDBusArgument &argument, const MyImage &image) {
          argument.beginStructure();
          argument << image.width;
          argument << image.height;
          argument << image.rowStride;
          argument << image.data;
          argument.endStructure();
          return argument;
      }
      
      inline const QDBusArgument &operator>>(const QDBusArgument &argument, MyImage &image) {
          argument.beginStructure();
          argument >> image.width;
          argument >> image.height;
          argument >> image.rowStride;
          argument >> image.data;
          argument.endStructure();
          return argument;
      }
      
      Q_DECLARE_METATYPE(MyImage)
      
      qDBusRegisterMetaType<MyImage>();
      

      I can read the image like so

      QDBusPendingReply<QVariantMap> reply = ...;
      ...
      QVariantMap map = reply.value():
      auto dataArgument = map.value("data").value<QDBusArgument>();
      auto image = qdbus_cast<MyImage>(dataArgument);
      

      The qdbus_cast call will trigger an assert in libdbus if the structure sent by the client does not match the expected signature.

      I can only check currentType() being QDBusArgument::StructureType but I can't guarantee the fields inside the structure are the ones I expect.

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            broulik Kai Uwe Broulik
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes