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

QXdgDesktopPortalFileDialog sometimes breaks when selectedFilter is supplied

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • 6.0.0, 5.15
    • 5.15.1
    • None
    • Up-to-date Arch Linux with Qt 5.15.1 from its binary repositories, running KDE Plasma 5.19.5 on X11. Desktop Portals tested include both xdg-desktop-portal-gtk 1.8.0 and xdg-desktop-portal-kde 5.19.5.
    • Linux/X11
    • 45a0c68c8c0b373152f4aec511bc150f431ad9e3(6.0) 83a96cbc5113adcecaf5845be9f6c27efa6bf9d2(5.15)

    Description

      When the xdgdesktopportal platform theme is used, file dialogs are sometimes not shown when a selectedFilter is supplied. I have attached a small example program where this happens. To reproduce, simply compile that program and run it with the -platformtheme xdgdesktopportal option.

      Inspecting the D-Bus call that is issued when the program is run reveals that the current_filter option is set to an invalid value (that is, an empty filter name and no filter patterns):

      $ dbus-monitor --session interface=org.freedesktop.portal.FileChooser
      method call time=1601804612.365980 sender=:1.230 -> destination=org.freedesktop.portal.Desktop serial=69 path=/org/freedesktop/portal/desktop; interface=org.freedesktop.portal.FileChooser; member=OpenFile
         string "x11:0"
         string "Open File"
         array [
            dict entry(
               string "current_filter"
               variant             struct {
                     string ""
                     array [
                     ]
                  }
            )
            dict entry(
               string "directory"
               variant             boolean false
            )
            dict entry(
               string "filters"
               variant             array [
                     struct {
                        string "Image Files "
                        array [
                           struct {
                              uint32 0
                              string "*.jpeg"
                           }
                           struct {
                              uint32 0
                              string "*.jpg"
                           }
                           struct {
                              uint32 0
                              string "*.png"
                           }
                        ]
                     }
                     struct {
                        string "JPEG files "
                        array [
                           struct {
                              uint32 0
                              string "*.jpeg"
                           }
                           struct {
                              uint32 0
                              string "*.jpg"
                           }
                        ]
                     }
                     struct {
                        string "PNG files "
                        array [
                           struct {
                              uint32 0
                              string "*.png"
                           }
                        ]
                     }
                  ]
            )
            dict entry(
               string "handle_token"
               variant             string "qt1053640879"
            )
            dict entry(
               string "modal"
               variant             boolean true
            )
            dict entry(
               string "multiple"
               variant             boolean false
            )
         ]
      

      The reason for this is that when the D-Bus method call is prepared, the value for the current_filter option is saved as a pointer to a QVector entry. When that QVector is subsequently appended to and needs to be resized, the pointer starts dangling, leading to the invalid method call shown above. The relevant code can be found here.

      This bug was not present in Qt 5.15.0, however that's only because that version did not support the current_filter option in the first place (QTBUG-85658); hence why I haven't marked this bug as a regression.

      Attachments

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

        Activity

          People

            peppe Giuseppe D'Angelo
            j5lx Jakob Gahde
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes