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

QFileInfo::canonicalPath is wrongly resolved for relative paths containing ../

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 5.15.1
    • None
    • $/opt/mxe/usr/x86_64-w64-mingw32.shared.posix/qt5/bin/qmake --version
      QMake version 3.1
      Using Qt version 5.15.1 in /opt/mxe/usr/x86_64-w64-mingw32.shared.posix/qt5/lib
    • Linux/X11

    Description

      Hi,

       

      well, it's a bit hard to explain. The Qt 5.15.1 upgrade broke our test environment (no problem with Qt 5.13 so far). We cross-compile our application (Linux host, MinGW 64 build), and we run our tests on Linux host with wine.

       

      We noticed "Broken filename passed to function" errors in the logs, and I managed to find a bug in the QFileInfo::canonicalFilePath()'s function. When the path is relative and contains a "../" inside, the resolved path will be wrong.

       

      Example code to trigger the issue:

      #include <QCoreApplication>
      #include <QDebug>
      #include <QDirIterator>
      #include <QFileInfo>
      #include <iostream>
      
      int
      main(int argc, char *argv[])
      {
        QCoreApplication a(argc, argv);
        Q_UNUSED(a)
      
        const auto somePath = qEnvironmentVariable("SOME_PATH", QStringLiteral("/tmp"));
        QFileInfo info(somePath);
      
        std::cout << "cannonicalFilePath " << info.canonicalFilePath().toStdString() << std::endl;
      
        QDirIterator it(info.canonicalFilePath(), QDirIterator::Subdirectories);
      
        while (it.hasNext())
          {
            QString file = it.next();
      
            if (it.fileInfo().isFile())
              {
                std::cout << "  file " << file.toStdString() << std::endl;
              }
          }
      
        return 0;
      }

       

      Output when it's working as expected:

      $SOME_PATH=$PWD/ /usr/bin/wine ./brokenfilenameqt5151.exe 
      0068:err:ole:start_rpcss Failed to start RpcSs service
      cannonicalFilePath Z:/mnt/home/tomi/zwa/projects/adp-developing-2.0/source/adp/brokenfilenameqt5151/aaa
        file Z:/mnt/home/tomi/zwa/projects/adp-developing-2.0/source/adp/brokenfilenameqt5151/aaa/brokenfilenameqt5151.exe
        file Z:/mnt/home/tomi/zwa/projects/adp-developing-2.0/source/adp/brokenfilenameqt5151/aaa/commands.txt
        file Z:/mnt/home/tomi/zwa/projects/adp-developing-2.0/source/adp/brokenfilenameqt5151/aaa/main.o
        file Z:/mnt/home/tomi/zwa/projects/adp-developing-2.0/source/adp/brokenfilenameqt5151/aaa/Makefile
        file Z:/mnt/home/tomi/zwa/projects/adp-developing-2.0/source/adp/brokenfilenameqt5151/aaa/strace_fail.txt
        file Z:/mnt/home/tomi/zwa/projects/adp-developing-2.0/source/adp/brokenfilenameqt5151/aaa/strace_success.txt
        file Z:/mnt/home/tomi/zwa/projects/adp-developing-2.0/source/adp/brokenfilenameqt5151/aaa/winedebug_fail.txt
        file Z:/mnt/home/tomi/zwa/projects/adp-developing-2.0/source/adp/brokenfilenameqt5151/aaa/winedebug_success.txt 

       

      Output when it is not working:

      $SOME_PATH=$PWD/../aaa /usr/bin/wine ./brokenfilenameqt5151.exe 
      0068:err:ole:start_rpcss Failed to start RpcSs service
      cannonicalFilePath Z:/mnt/home/tomi/zwa/projects/adp-developing-2.0/source/adp/brokenfilenameqt5151/aaa../aaa 
      
      $ls $PWD/../aaa -1
      brokenfilenameqt5151.exe
      commands.txt
      main.o
      Makefile
      strace_fail.txt
      strace_success.txt
      winedebug_fail.txt
      winedebug_success.txt

       

      The problem is that the canonical file path is wrong.

      Z:/mnt/home/tomi/zwa/projects/adp-developing-2.0/source/adp/brokenfilenameqt5151/aaa     missind a '/' here    ../aaa

       

      I have also attached a sample project with debug outputs with strace and wine logs.

       

      Most probably this was an issue with our qmltestcase test apps, where the -import path stopped working for us, and had to change the deployment for our tests to be able to run it them with wine.

       

      This might be related to this bug: https://bugreports.qt.io/browse/QTBUG-86504

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            tomicooler Tamás Dömők
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes