From 7da0549b8c742c8efd3df5f0ed26e93b822b56c1 Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Tue, 4 Oct 2022 18:21:10 +0200 Subject: [PATCH] operator [0] on empty vector crashes Issue #763 --- core/debug/debug_agent.h | 5 ++++- core/rend/boxart/gamesdb.cpp | 2 +- core/rend/boxart/pvrparser.h | 2 +- core/rend/boxart/scraper.cpp | 9 +++++++-- core/rend/gles/opengl_driver.cpp | 3 ++- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/core/debug/debug_agent.h b/core/debug/debug_agent.h index 78d05ee9f..1cd1f3b11 100644 --- a/core/debug/debug_agent.h +++ b/core/debug/debug_agent.h @@ -295,7 +295,10 @@ public: { verify(!Sh4cntx.CpuRunning); size = stack.size() * 8; - return (const u32 *)&stack[0]; + if (!stack.empty()) + return (const u32 *)&stack[0]; + else + return nullptr; } void subroutineCall() diff --git a/core/rend/boxart/gamesdb.cpp b/core/rend/boxart/gamesdb.cpp index ee818df60..cf1a56c69 100644 --- a/core/rend/boxart/gamesdb.cpp +++ b/core/rend/boxart/gamesdb.cpp @@ -88,7 +88,7 @@ json TheGamesDb::httpGet(const std::string& url) blackoutPeriod = os_GetSeconds() + 60.0; else if (!success) blackoutPeriod = os_GetSeconds() + 1.0; - if (!success) + if (!success || receivedData.empty()) throw std::runtime_error("http error"); std::string content((const char *)&receivedData[0], receivedData.size()); diff --git a/core/rend/boxart/pvrparser.h b/core/rend/boxart/pvrparser.h index 5d97f5af2..a4775fbc7 100644 --- a/core/rend/boxart/pvrparser.h +++ b/core/rend/boxart/pvrparser.h @@ -120,7 +120,7 @@ static bool pvrParse(const u8 *data, u32 len, u32& width, u32& height, std::vect WARN_LOG(COMMON, "Unsupported PVR pixel type: %d", pixelFormat); return false; } - DEBUG_LOG(COMMON, "PVR file: size %d pixelFmt %d imgType %d w %d h %d\n", size, pixelFormat, imgType, width, height); + DEBUG_LOG(COMMON, "PVR file: size %d pixelFmt %d imgType %d w %d h %d", size, pixelFormat, imgType, width, height); u32 texU = 3; while (1u << texU < width) texU++; diff --git a/core/rend/boxart/scraper.cpp b/core/rend/boxart/scraper.cpp index e2f3ebf55..92c5e95e3 100644 --- a/core/rend/boxart/scraper.cpp +++ b/core/rend/boxart/scraper.cpp @@ -33,12 +33,17 @@ bool Scraper::downloadImage(const std::string& url, const std::string& localName std::string contentType; if (!http::success(http::get(url, content, contentType))) { - WARN_LOG(COMMON, "download_image http error: %s", url.c_str()); + WARN_LOG(COMMON, "downloadImage http error: %s", url.c_str()); return false; } if (contentType.substr(0, 6) != "image/") { - WARN_LOG(COMMON, "download_image bad content type %s", contentType.c_str()); + WARN_LOG(COMMON, "downloadImage bad content type %s", contentType.c_str()); + return false; + } + if (content.empty()) + { + WARN_LOG(COMMON, "downloadImage: empty content"); return false; } FILE *f = nowide::fopen(localName.c_str(), "wb"); diff --git a/core/rend/gles/opengl_driver.cpp b/core/rend/gles/opengl_driver.cpp index 8641195cd..3da0b7107 100644 --- a/core/rend/gles/opengl_driver.cpp +++ b/core/rend/gles/opengl_driver.cpp @@ -68,7 +68,8 @@ OpenGLDriver::~OpenGLDriver() texIds.push_back((GLuint)(uintptr_t)crosshairTexId); for (const auto& it : textures) texIds.push_back((GLuint)(uintptr_t)it.second); - glcache.DeleteTextures(texIds.size(), &texIds[0]); + if (!texIds.empty()) + glcache.DeleteTextures(texIds.size(), &texIds[0]); ImGui_ImplOpenGL3_Shutdown(); }