mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-12-02 02:33:43 +01:00
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:
1 parent
06522e91a0
commit
17d899d2d3
1 file changed
+5
-1
+5
-1
@@ -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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user