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

QZipReader::extractAll wrongly creates directories for entries in zip root dir

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • P1: Critical
    • 6.9.0 FF
    • 6.8.0
    • Core: I/O
    • None
    • All
    • 4f9cbd5b2 (dev)

    Description

      If a zip file does not contain directory entries but contains files in both no directory (root of zip) and files with directories during extractAll directories will be created for the root dir entries.

      E.g. in a zip file with:

      a.txt
      b/c.txt
      

       
      extractAll tries to create a dir named "a.txt" and then later fails on writing the file a.txt.
      This happens if the zip file does not contain directory entries itself. Seems famous libs like the python zipfile are creating those zip files.

      The problematic code is here: (hasDirs is true, foundDirs is false)

      https://codebrowser.dev/qt6/qtbase/src/corelib/io/qzip.cpp.html#1010

          // Some zip archives can be broken in the sense that they do not report
          // separate entries for directories, only for files. In this case we
          // need to recreate directory structure based on the file paths.
          if (hasDirs && !foundDirs) {
              for (const FileInfo &fi : allFiles) {
                  const auto dirPath = fi.filePath.left(fi.filePath.lastIndexOf(u"/"));
                  if (!baseDir.mkpath(dirPath))
                      return false;
                  // We will leave the directory permissions default in this case,
                  // because setting dir permissions based on file is incorrect
              }
          }
      

      an easy fix would be to add a line like

        // after: for (const FileInfo &fi : allFiles) {
          if (!fi.filePath.contains(u"/")) continue; // still assuming that the zip files has either none dir entries or for all directories consistent ones
      

      A better (more robust) fix would be to check for each entry whether the directory needs to be created.
       

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            mbehr1 Matthias Behr
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes