From 7b08ae37479a628e25b7857f377fe5a2955e9518 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 9 Mar 2016 17:30:02 -0800 Subject: [PATCH] drop invalid mappings on AssetServer load --- assignment-client/src/assets/AssetServer.cpp | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/assignment-client/src/assets/AssetServer.cpp b/assignment-client/src/assets/AssetServer.cpp index da1a7d3163..f37c6d706e 100644 --- a/assignment-client/src/assets/AssetServer.cpp +++ b/assignment-client/src/assets/AssetServer.cpp @@ -453,6 +453,30 @@ void AssetServer::loadMappingsFromFile() { if (error.error == QJsonParseError::NoError) { _fileMappings = jsonDocument.object().toVariantHash(); + // remove any mappings that don't match the expected format + auto it = _fileMappings.begin(); + while (it != _fileMappings.end()) { + bool shouldDrop = false; + + if (it.key()[0] != '/') { + qWarning() << "Will not keep mapping for" << it.key() << "since it does not have a leading forward slash."; + shouldDrop = true; + } + + QRegExp hashFileRegex { "^[A-Fa-f0-9]{" + QString::number(SHA256_HASH_HEX_LENGTH) + "}$" }; + + if (!hashFileRegex.exactMatch(it.value().toString())) { + qWarning() << "Will not keep mapping for" << it.key() << "since it does not have a valid hash."; + shouldDrop = true; + } + + if (shouldDrop) { + it = _fileMappings.erase(it); + } else { + ++it; + } + } + qInfo() << "Loaded" << _fileMappings.count() << "mappings from map file at" << mapFilePath; return; }