From 62d5e0b1b96bfdf0993a6884adb4019b0cc6e407 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Fri, 13 Oct 2023 15:01:23 -0400 Subject: [PATCH] common: Fix use-after-free bug with QLatin1String in FileCache --- common/include/filecache.h | 8 ++++---- common/src/filecache.cpp | 10 ++++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/common/include/filecache.h b/common/include/filecache.h index 3cb3d02..faabe15 100644 --- a/common/include/filecache.h +++ b/common/include/filecache.h @@ -16,12 +16,12 @@ class FileCache public: explicit FileCache(GameData &data); - bool fileExists(const QLatin1String &path); - physis_Buffer &lookupFile(const QLatin1String &path); + bool fileExists(const QString &path); + physis_Buffer &lookupFile(const QString &path); private: - QMap cachedBuffers; - QHash cachedExist; + QMap cachedBuffers; + QHash cachedExist; GameData &data; QMutex bufferMutex, existMutex; }; \ No newline at end of file diff --git a/common/src/filecache.cpp b/common/src/filecache.cpp index 8de6149..6a2f99d 100644 --- a/common/src/filecache.cpp +++ b/common/src/filecache.cpp @@ -10,23 +10,25 @@ FileCache::FileCache(GameData &data) { } -physis_Buffer &FileCache::lookupFile(const QLatin1String &path) +physis_Buffer &FileCache::lookupFile(const QString &path) { QMutexLocker locker(&bufferMutex); if (!cachedBuffers.contains(path)) { - cachedBuffers[path] = physis_gamedata_extract_file(&data, path.data()); + std::string pathstd = path.toStdString(); + cachedBuffers[path] = physis_gamedata_extract_file(&data, pathstd.c_str()); } return cachedBuffers[path]; } -bool FileCache::fileExists(const QLatin1String &path) +bool FileCache::fileExists(const QString &path) { QMutexLocker locker(&existMutex); if (!cachedExist.contains(path)) { - cachedExist[path] = physis_gamedata_exists(&data, path.data()); + std::string pathstd = path.toStdString(); + cachedExist[path] = physis_gamedata_exists(&data, pathstd.c_str()); } return cachedExist[path];