aboutsummaryrefslogtreecommitdiff
path: root/x11/kdelibs4/files/patch-git_dd1c2da
blob: f70609e81c867582d69be3d97536df97f8a09825 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
From dd1c2da9d26fd4cfc7fe0a25f413e536d56cf2db Mon Sep 17 00:00:00 2001
From: Albert Astals Cid <aacid@kde.org>
Date: Fri, 26 Aug 2016 00:30:34 +0200
Subject: [PATCH] Backport karchive fix for out of directory files

REVIEW: 128749
---
 kdecore/io/karchive.cpp                              |  15 +++++++++++++--

diff --git kdecore/io/karchive.cpp kdecore/io/karchive.cpp
index eb0bf2e..d3f8c67 100644
--- kdecore/io/karchive.cpp
+++ kdecore/io/karchive.cpp
@@ -800,6 +800,7 @@ static bool sortByPosition( const KArchiveFile* file1, const KArchiveFile* file2
 void KArchiveDirectory::copyTo(const QString& dest, bool recursiveCopy ) const
 {
   QDir root;
+  const QString destDir(QDir(dest).absolutePath()); // get directory path without any "." or ".."

   QList<const KArchiveFile*> fileList;
   QMap<qint64, QString> fileToDir;
@@ -809,10 +810,20 @@ void KArchiveDirectory::copyTo(const QString& dest, bool recursiveCopy ) const
   QStack<QString> dirNameStack;

   dirStack.push( this );     // init stack at current directory
-  dirNameStack.push( dest ); // ... with given path
+  dirNameStack.push( destDir ); // ... with given path
   do {
     const KArchiveDirectory* curDir = dirStack.pop();
-    const QString curDirName = dirNameStack.pop();
+
+    // extract only to specified folder if it is located within archive's extraction folder
+    // otherwise put file under root position in extraction folder
+    QString curDirName = dirNameStack.pop();
+    if (!QDir(curDirName).absolutePath().startsWith(destDir)) {
+        qWarning() << "Attempted export into folder" << curDirName
+            << "which is outside of the extraction root folder" << destDir << "."
+            << "Changing export of contained files to extraction root folder.";
+        curDirName = destDir;
+    }
+
     root.mkdir(curDirName);

     const QStringList dirEntries = curDir->entries();