From 17d899d2d3668bbb6a09071ac0efa74d5771041b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 11 Aug 2026 15:05:11 +0200 Subject: [PATCH] Replay: avoid size_t wraparound in side-data truncation check ReplayExecuteBlob's bounds check (i + item.info.size > sz) can overflow on platforms where size_t is 32-bit, since item.info.size is a client/file-supplied u32 read from replay.execute's base64 blob - a crafted value near UINT32_MAX could wrap the sum below sz, passing the check before an out-of-bounds memcpy. Use a subtraction-based check instead, which can't overflow regardless of size_t width. --- Core/Replay.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Core/Replay.cpp b/Core/Replay.cpp index 0ada57ca94..0a500d5343 100644 --- a/Core/Replay.cpp +++ b/Core/Replay.cpp @@ -153,7 +153,11 @@ bool ReplayExecuteBlob(int version, const std::vector &data) { i += sizeof(ReplayItemHeader); if ((int)item.info.action & (int)ReplayAction::MASK_SIDEDATA) { - if (i + item.info.size > sz) { + // Subtraction-based check (rather than i + item.info.size > sz) avoids + // wraparound on platforms where size_t is 32-bit, where a large enough + // item.info.size could otherwise make the addition overflow and wrap + // below sz, defeating this bounds check before the memcpy below. + if (item.info.size > sz - i) { ERROR_LOG(Log::System, "Truncated replay data at %lld during side data", (long long)i); break; }