Fix MMCZip bugs

Signed-off-by: timoreo <contact@timoreo.fr>
This commit is contained in:
timoreo 2022-07-01 14:03:45 +02:00
parent a97387b692
commit 98a82cd484
No known key found for this signature in database
GPG Key ID: 121A72C3512BA288

View File

@ -300,6 +300,11 @@ std::optional<QStringList> MMCZip::extractSubDir(QuaZip *zip, const QString & su
name.remove(0, subdir.size());
auto original_name = name;
// Fix subdirs/files ending with a / getting transformed into absolute paths
if(name.startsWith('/')){
name = name.mid(1);
}
// Fix weird "folders with a single file get squashed" thing
QString path;
if(name.contains('/') && !name.endsWith('/')){
@ -319,6 +324,11 @@ std::optional<QStringList> MMCZip::extractSubDir(QuaZip *zip, const QString & su
absFilePath = directory.absoluteFilePath(path + name);
}
//Block potential file traversal issues
if(!absFilePath.startsWith(directory.absolutePath())){
qWarning() << "Potential file traversal issue, for path " << absFilePath << " with base name as " << directory.absolutePath();
continue;
}
if (!JlCompress::extractFile(zip, "", absFilePath))
{
qWarning() << "Failed to extract file" << original_name << "to" << absFilePath;