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.
This commit is contained in:
Henrik Rydgård committed 2026-08-11 15:40:30 +02:00
1 parent 06522e91a0
commit 17d899d2d3
1 file changed
+5 -1
+5 -1
View File
@@ -153,7 +153,11 @@ bool ReplayExecuteBlob(int version, const std::vector<uint8_t> &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;
}