diff options
author | Sefa Eyeoglu <contact@scrumplex.net> | 2023-02-10 09:17:48 +0100 |
---|---|---|
committer | Sefa Eyeoglu <contact@scrumplex.net> | 2023-02-10 09:17:48 +0100 |
commit | 6be7eed878bc701407c6c3efd93d9944e1079490 (patch) | |
tree | 4ebb5e988be4793894e99dad56743b089383b461 /launcher/MMCZip.cpp | |
parent | f36c3a3f6c795f1aa6b3dc9ff6f151b077531aaa (diff) | |
download | PrismLauncher-6be7eed878bc701407c6c3efd93d9944e1079490.tar.gz PrismLauncher-6be7eed878bc701407c6c3efd93d9944e1079490.tar.bz2 PrismLauncher-6be7eed878bc701407c6c3efd93d9944e1079490.zip |
fix: don't extract files outside of target path
This should fix a security issue regarding path traversal in zip files.
Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
Diffstat (limited to 'launcher/MMCZip.cpp')
-rw-r--r-- | launcher/MMCZip.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/launcher/MMCZip.cpp b/launcher/MMCZip.cpp index f6600343..734eacd8 100644 --- a/launcher/MMCZip.cpp +++ b/launcher/MMCZip.cpp @@ -275,7 +275,8 @@ bool MMCZip::findFilesInZip(QuaZip * zip, const QString & what, QStringList & re // ours std::optional<QStringList> MMCZip::extractSubDir(QuaZip *zip, const QString & subdir, const QString &target) { - QDir directory(target); + auto absDirectoryUrl = QUrl::fromLocalFile(target); + QStringList extracted; qDebug() << "Extracting subdir" << subdir << "from" << zip->getZipName() << "to" << target; @@ -317,11 +318,16 @@ std::optional<QStringList> MMCZip::extractSubDir(QuaZip *zip, const QString & su QString absFilePath; if(name.isEmpty()) { - absFilePath = directory.absoluteFilePath(name) + "/"; + absFilePath = FS::PathCombine(target, "/"); // FIXME this seems weird } else { - absFilePath = directory.absoluteFilePath(path + name); + absFilePath = FS::PathCombine(target, path + name); + } + + if (!absDirectoryUrl.isParentOf(QUrl::fromLocalFile(absFilePath))) { + qWarning() << "Extracting" << name << "was cancelled, because it was effectively outside of the target path" << target; + return std::nullopt; } if (!JlCompress::extractFile(zip, "", absFilePath)) |