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
For Gerrit Dashboard: QTBUG-131008 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
604695,2 | QZipReader: extractAll should not create dir for root entries | dev | qt/qtbase | Status: MERGED | +2 | 0 |