fix heap overflow with unstable version comparation

fixes #5210
fixes #5251 (the removeDuplicates line)

The issue was mostly with the Version parsing and compring
implementation.
Refactored that based on the https://git.sleeping.town/exa/FlexVer
examples.

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2026-03-24 20:05:37 +02:00
parent 156b7f365e
commit 5a0931d3cf
No known key found for this signature in database
GPG key ID: 55EF5DA53DB36318
4 changed files with 175 additions and 226 deletions

View file

@ -22,6 +22,8 @@
#include <QDebug>
#include <QDir>
#include <QObject>
#include <algorithm>
#include <compare>
#include <sstream>
#include <string>
#include <utility>
@ -91,6 +93,15 @@ auto intEntry(toml::table table, QString entry_name) -> int
return node.value_or(0);
}
bool sortMCVersions(const QString& a, const QString& b)
{
auto cmp = Version(a) <=> Version(b);
if (cmp == std::strong_ordering::equal) {
return a < b;
}
return cmp == std::strong_ordering::less;
};
auto V1::createModFormat([[maybe_unused]] const QDir& index_dir,
ModPlatform::IndexedPack& mod_pack,
ModPlatform::IndexedVersion& mod_version) -> Mod
@ -117,8 +128,8 @@ auto V1::createModFormat([[maybe_unused]] const QDir& index_dir,
mod.side = mod_version.side == ModPlatform::Side::NoSide ? mod_pack.side : mod_version.side;
mod.loaders = mod_version.loaders;
mod.mcVersions = mod_version.mcVersion;
std::sort(mod.mcVersions.begin(), mod.mcVersions.end(),
[](QString a, QString b) { return Version(std::move(a)) < Version(std::move(b)); });
mod.mcVersions.removeDuplicates();
std::ranges::sort(mod.mcVersions, sortMCVersions);
mod.releaseType = mod_version.version_type;
mod.version_number = mod_version.version_number;
@ -304,8 +315,8 @@ auto V1::getIndexForMod(const QDir& index_dir, QString slug) -> Mod
}
}
}
std::sort(mod.mcVersions.begin(), mod.mcVersions.end(),
[](QString a, QString b) { return Version(std::move(a)) < Version(std::move(b)); });
mod.mcVersions.removeDuplicates();
std::ranges::sort(mod.mcVersions, sortMCVersions);
}
}
mod.version_number = table["x-prismlauncher-version-number"].value_or("");