Claude being too cautious. Let's just reject bad values fully.

This commit is contained in:
Henrik Rydgård committed 2026-08-11 20:08:01 +02:00
1 parent 3806d00e58
commit a3e0f915af
1 file changed
+2 -2
+2 -2
View File
@@ -459,11 +459,11 @@ void BlockAllocator::DoState(PointerWrap &p)
// A corrupt/malicious savestate could claim an enormous block count. Each
// block needs at least sizeof(start)+sizeof(size)+sizeof(taken)+sizeof(tag)
// bytes in the stream, so clamp to what could plausibly still be there
// instead of always trying to allocate `count` Blocks up front.
// bytes in the stream. Reject totally outlandish values, and also if count is now sub-zero.
size_t maxRemainingBlocks = p.Remaining() / (sizeof(u32) + sizeof(u32) + 1 + 32);
if (count < 0) {
count = 0;
p.SetError(PointerWrap::ERROR_FAILURE);
} else if ((size_t)count > maxRemainingBlocks) {
count = (int)maxRemainingBlocks;
p.SetError(PointerWrap::ERROR_FAILURE);