From 6929a0d9ae3854b4906ce6d8d384e7c1ae545e2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 11 Aug 2026 15:05:00 +0200 Subject: [PATCH] GPUBufferSubscriber: bound stackWidth and validate texture level gpu.buffer.*'s "uri" output type let a client supply an arbitrary stackWidth with no upper bound, used as the starting divisor in a loop that decrements until it evenly divides the buffer's actual (small) pixel count - a client sending a huge stackWidth (up to ~2 billion) stalls the connection's handler thread for that many iterations. Clamp it to the actual pixel count first. gpu.buffer.texture's level parameter was forwarded as-is (u32) into GPU_GetCurrentTexture(), which takes a plain int - a client-supplied value whose u32->int conversion is negative skips backends' "level >= mip count" bounds check (which only fires for level > 0), reaching backend texture-copy code with a bogus mip index. Reject it upfront. --- Core/Debugger/WebSocket/GPUBufferSubscriber.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Core/Debugger/WebSocket/GPUBufferSubscriber.cpp b/Core/Debugger/WebSocket/GPUBufferSubscriber.cpp index 483ec4e9b6..d7e8e92def 100644 --- a/Core/Debugger/WebSocket/GPUBufferSubscriber.cpp +++ b/Core/Debugger/WebSocket/GPUBufferSubscriber.cpp @@ -51,8 +51,12 @@ static bool StreamBufferToDataURI(DebuggerRequest &req, const GPUDebugBuffer &bu if (stackWidth > 0) { u32 totalPixels = w * h; - w = stackWidth; - while ((totalPixels % w) != 0) + // stackWidth is client-supplied and otherwise unbounded; since totalPixels + // is the real (small) buffer size, clamping to it bounds this loop to at + // most totalPixels iterations instead of up to ~2 billion for a huge value. + // Keep it at least 1 to avoid a divide by zero below. + w = std::max(1, std::min((u32)stackWidth, totalPixels)); + while (w > 1 && (totalPixels % w) != 0) --w; h = totalPixels / w; } @@ -384,6 +388,12 @@ void WebSocketGPUBufferTexture(DebuggerRequest &req) { u32 level = 0; if (!req.ParamU32("level", &level, false, DebuggerParamType::OPTIONAL)) return; + // GPU_GetCurrentTexture() takes a plain int; a client-supplied value whose + // u32->int conversion is negative would skip backends' "level >= mip count" + // bounds check (which only fires for level > 0), reaching backend texture-copy + // code with a bogus mip index. + if (level > 0x7FFFFFFF) + return req.Fail("Invalid level"); GenericStreamBuffer(req, [level](const GPUDebugBuffer *&buf, bool *isFramebuffer) { return GPUStepping::GPU_GetCurrentTexture(buf, level, isFramebuffer);