From a20c972d556e14024e09a2757efb1265eadfa9ea Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 31 Jan 2021 09:21:40 -0800 Subject: [PATCH] Loaders: Prevent errors on 0 byte reads. Was happening when opening an http:// GE frame dump. --- Core/FileLoaders/DiskCachingFileLoader.cpp | 7 +++++++ Core/FileLoaders/LocalFileLoader.cpp | 3 +++ 2 files changed, 10 insertions(+) diff --git a/Core/FileLoaders/DiskCachingFileLoader.cpp b/Core/FileLoaders/DiskCachingFileLoader.cpp index 412f409a84..93b2bebd38 100644 --- a/Core/FileLoaders/DiskCachingFileLoader.cpp +++ b/Core/FileLoaders/DiskCachingFileLoader.cpp @@ -98,6 +98,10 @@ size_t DiskCachingFileLoader::ReadAt(s64 absolutePos, size_t bytes, void *data, // While in case the cache size is too small for the entire read. while (readSize < bytes) { readSize += cache_->SaveIntoCache(backend_, absolutePos + readSize, bytes - readSize, (u8 *)data + readSize, flags); + // We're done, nothing more to read. + if (readSize == bytes) { + break; + } // If there are already-cached blocks afterward, we have to read them. size_t bytesFromCache = cache_->ReadFromCache(absolutePos + readSize, bytes - readSize, (u8 *)data + readSize); readSize += bytesFromCache; @@ -441,6 +445,9 @@ bool DiskCachingFileLoaderCache::ReadBlockData(u8 *dest, BlockInfo &info, size_t if (!f_) { return false; } + if (size == 0) { + return true; + } s64 blockOffset = GetBlockOffset(info.block); // Before we read, make sure the buffers are flushed. diff --git a/Core/FileLoaders/LocalFileLoader.cpp b/Core/FileLoaders/LocalFileLoader.cpp index 1a6205bfab..232f3764a8 100644 --- a/Core/FileLoaders/LocalFileLoader.cpp +++ b/Core/FileLoaders/LocalFileLoader.cpp @@ -119,6 +119,9 @@ std::string LocalFileLoader::Path() const { } size_t LocalFileLoader::ReadAt(s64 absolutePos, size_t bytes, size_t count, void *data, Flags flags) { + if (bytes == 0) + return 0; + #if PPSSPP_PLATFORM(SWITCH) // Toolchain has no fancy IO API. We must lock. std::lock_guard guard(readLock_);