From ef87fe2e74e5e1f3eba5a45a92da4e7544481991 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 9 Aug 2026 15:58:50 +0200 Subject: [PATCH 1/2] ManagedTexture: fix file buffer leak on failed image decode TextureLoadTask::Run() only freed the VFS-read file buffer on the success path - a corrupt/truncated image in a texture pack or replacement texture directory (valid magic, bad payload) leaked the whole file's bytes on every load attempt. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01L4QAoxV2KY7ek4PcZw3WvY --- Common/Render/ManagedTexture.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Common/Render/ManagedTexture.cpp b/Common/Render/ManagedTexture.cpp index bc36a2aca5..ef4a46ddc1 100644 --- a/Common/Render/ManagedTexture.cpp +++ b/Common/Render/ManagedTexture.cpp @@ -40,13 +40,9 @@ public: return; } - if (!tempImage_->LoadTextureLevelsFromFileData(buffer, fileSize, type_)) { - *state_ = ManagedTexture::LoadState::FAILED; - waitable_->Notify(); - return; - } + bool success = tempImage_->LoadTextureLevelsFromFileData(buffer, fileSize, type_); delete[] buffer; - *state_ = ManagedTexture::LoadState::SUCCESS; + *state_ = success ? ManagedTexture::LoadState::SUCCESS : ManagedTexture::LoadState::FAILED; waitable_->Notify(); } From 1a9f2f827f539fa95075dca17ffdb0832652a6cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 9 Aug 2026 15:58:56 +0200 Subject: [PATCH 2/2] DrawBuffer::V(): don't overflow verts_ in release builds The only guard against writing past the fixed 65536-entry verts_ array was _dbg_assert_msg_, which is compiled out entirely outside _DEBUG - a large enough single batch (e.g. Circle()/CircleSegment() with a big segment count, or a large UI list without an intervening Flush()) silently corrupted the heap in release builds. Added a real bounds check that drops the vertex instead. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01L4QAoxV2KY7ek4PcZw3WvY --- Common/Render/DrawBuffer.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Common/Render/DrawBuffer.h b/Common/Render/DrawBuffer.h index c73abae598..94e5e56095 100644 --- a/Common/Render/DrawBuffer.h +++ b/Common/Render/DrawBuffer.h @@ -89,6 +89,11 @@ public: void V(float x, float y, float z, uint32_t color, float u, float v) { _dbg_assert_msg_(count_ < MAX_VERTS, "Overflowed the DrawBuffer"); + if (count_ >= MAX_VERTS) { + // _dbg_assert_msg_ above is compiled out in release builds - don't write + // past the end of verts_ there either, just drop the vertex. + return; + } #ifdef _DEBUG if (my_isnanorinf(x) || my_isnanorinf(y) || my_isnanorinf(z)) {