aboutsummaryrefslogtreecommitdiff
path: root/launcher
diff options
context:
space:
mode:
authorTheKodeToad <TheKodeToad@proton.me>2023-08-22 14:09:44 +0100
committerGitHub <noreply@github.com>2023-08-22 14:09:44 +0100
commit0e9611111638bfbb15e55270d2d9d0460fe32d58 (patch)
tree2cffa5a34a0220f09a8962483f89930fe6c07d85 /launcher
parentb1783d8fb1bf84a0c12412dd3499175a9e597a95 (diff)
parent7acfe36a625e2f0c4fb5ba9c11a15be45484a4f6 (diff)
downloadPrismLauncher-0e9611111638bfbb15e55270d2d9d0460fe32d58.tar.gz
PrismLauncher-0e9611111638bfbb15e55270d2d9d0460fe32d58.tar.bz2
PrismLauncher-0e9611111638bfbb15e55270d2d9d0460fe32d58.zip
Merge pull request #1556 from Trial97/metacache
Gracefully handle invalid cache metadata
Diffstat (limited to 'launcher')
-rw-r--r--launcher/net/HttpMetaCache.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/launcher/net/HttpMetaCache.cpp b/launcher/net/HttpMetaCache.cpp
index 7809d40f..f37bc0bf 100644
--- a/launcher/net/HttpMetaCache.cpp
+++ b/launcher/net/HttpMetaCache.cpp
@@ -218,9 +218,24 @@ void HttpMetaCache::Load()
if (!index.open(QIODevice::ReadOnly))
return;
- QJsonDocument json = QJsonDocument::fromJson(index.readAll());
+ QJsonParseError parseError;
+ QJsonDocument json = QJsonDocument::fromJson(index.readAll(), &parseError);
+
+ // Fail if the JSON is invalid.
+ if (parseError.error != QJsonParseError::NoError) {
+ qCritical() << QString("Failed to parse HttpMetaCache file: %1 at offset %2")
+ .arg(parseError.errorString(), QString::number(parseError.offset))
+ .toUtf8();
+ return;
+ }
+
+ // Make sure the root is an object.
+ if (!json.isObject()) {
+ qCritical() << "HttpMetaCache root should be an object.";
+ return;
+ }
- auto root = Json::requireObject(json, "HttpMetaCache root");
+ auto root = json.object();
// check file version first
auto version_val = Json::ensureString(root, "version");