Fix invalid characters filename download on windows

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
(cherry picked from commit e068120375)
This commit is contained in:
Trial97 2024-04-30 22:56:03 +03:00 committed by github-actions[bot]
parent b679a57939
commit a57a21af3b
3 changed files with 15 additions and 3 deletions

View File

@ -537,7 +537,12 @@ void FlameCreationTask::setupDownloadJob(QEventLoop& loop)
selectedOptionalMods = optionalModDialog.getResult(); selectedOptionalMods = optionalModDialog.getResult();
} }
for (const auto& result : results) { for (const auto& result : results) {
auto relpath = FS::PathCombine(result.targetFolder, result.fileName); auto fileName = result.fileName;
#ifdef Q_OS_WIN
fileName = FS::RemoveInvalidPathChars(fileName);
#endif
auto relpath = FS::PathCombine(result.targetFolder, fileName);
if (!result.required && !selectedOptionalMods.contains(relpath)) { if (!result.required && !selectedOptionalMods.contains(relpath)) {
relpath += ".disabled"; relpath += ".disabled";
} }

View File

@ -238,11 +238,15 @@ bool ModrinthCreationTask::createInstance()
auto root_modpack_url = QUrl::fromLocalFile(root_modpack_path); auto root_modpack_url = QUrl::fromLocalFile(root_modpack_path);
for (auto file : m_files) { for (auto file : m_files) {
auto file_path = FS::PathCombine(root_modpack_path, file.path); auto fileName = file.path;
#ifdef Q_OS_WIN
fileName = FS::RemoveInvalidPathChars(fileName);
#endif
auto file_path = FS::PathCombine(root_modpack_path, fileName);
if (!root_modpack_url.isParentOf(QUrl::fromLocalFile(file_path))) { if (!root_modpack_url.isParentOf(QUrl::fromLocalFile(file_path))) {
// This means we somehow got out of the root folder, so abort here to prevent exploits // This means we somehow got out of the root folder, so abort here to prevent exploits
setError(tr("One of the files has a path that leads to an arbitrary location (%1). This is a security risk and isn't allowed.") setError(tr("One of the files has a path that leads to an arbitrary location (%1). This is a security risk and isn't allowed.")
.arg(file.path)); .arg(fileName));
return false; return false;
} }

View File

@ -84,6 +84,9 @@ auto HttpMetaCache::getEntry(QString base, QString resource_path) -> MetaEntryPt
auto HttpMetaCache::resolveEntry(QString base, QString resource_path, QString expected_etag) -> MetaEntryPtr auto HttpMetaCache::resolveEntry(QString base, QString resource_path, QString expected_etag) -> MetaEntryPtr
{ {
#ifdef Q_OS_WIN
resource_path = FS::RemoveInvalidPathChars(resource_path);
#endif
auto entry = getEntry(base, resource_path); auto entry = getEntry(base, resource_path);
// it's not present? generate a default stale entry // it's not present? generate a default stale entry
if (!entry) { if (!entry) {