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

Crash after registering an invalid resource file

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P4: Low
    • None
    • 5.13.0, 5.13.2, 5.15.16, 6.2.10, 6.5.3, 6.6.0
    • Core: Resource System
    • Windows 11, Windows 10 22H2
    • 21
    • e696bec76 (dev), 60d60dba7 (6.7), 06618fbeb (6.6), b7792d9b8 (tqtc/lts-6.5)
    • Foundations Sprint 97, Foundations Sprint 98, Foundations Sprint 99, Foundation Sprint 100, Foundation Sprint 101, Foundations Sprint 102, Foundation Sprint 103, Foundation Sprint 104, Foundation Sprint 105, Foundation Sprint 106, Foundation Sprint 107

    Description

      Summary

      // From resourcecrash.zip
      int main(int argc, char *argv[])
      {
          QCoreApplication app(argc, argv);
      
          QString srcPath = ":/bad-file.rcc";
          QString destPath = "bad-file-on-disk.rcc";
          QString otherPath = ":/good-file.txt";
      
          qDebug().noquote() << QString("Copying '%1' to '%2'").arg(srcPath, destPath);
          QFile::copy(srcPath, destPath);
      
          QFileInfo info(destPath);
          qDebug().noquote() << destPath << "exists?:" << info.exists() << QString("(%1 bytes)").arg(info.size());
      
          bool registered = QResource::registerResource(destPath);
          qDebug().noquote() << destPath << "registered?:" << registered;
      
          QFile otherFile(otherPath);
          qDebug() << "Opening" << otherPath;
          if (otherFile.open(QIODevice::ReadOnly))
              qDebug() << "Read data:" << otherFile.readAll();
          else
              qDebug() << "Failed to open file";
      }
      

       

      Using Qt 5.12.12, the application does not register the bad file and everything runs fine:

      Copying ':/bad-file.rcc' to 'bad-file-on-disk.rcc'
      bad-file-on-disk.rcc exists?: true (55876 bytes)
      bad-file-on-disk.rcc registered?: false
      Opening ":/good-file.txt"
      Read data: "Hello world!"
      

       

      Using Qt 5.15.16 or 6.x, the application registers the bad file. Subsequent attempts to access the resource system will crash:

      Copying ':/bad-file.rcc' to 'bad-file-on-disk.rcc'
      bad-file-on-disk.rcc exists?: true (55876 bytes)
      bad-file-on-disk.rcc registered?: true
      Opening ":/good-file.txt"
      ### CRASHES HERE
      

       

      Original report (title: "QResourceRoot::hash crash")
      A customer sent me a dmp: my application crashes when trying to load a js file. From the stack, it looks like there is an if that does not work properly.

      I'm not really sure and unfortunately I cannot provide the file causing this issue. But I think that the if at line 735 (and 744) should be as follow:

      if (node <= 0) // root
          return 0; 

      Attachments

        Issue Links

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

          Activity

            People

              cnn Qt Core & Network
              jozzolo José Del Romano
              Vladimir Minenko Vladimir Minenko
              Alex Blasche Alex Blasche
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews