Skip to content

Commit 5ab2398

Browse files
committed
SaveStates: Reject unrealistic memory allocations
1 parent db543e0 commit 5ab2398

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

rpcs3/Emu/Cell/lv2/sys_prx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ std::function<void(void*)> lv2_prx::load(utils::serial& ar)
324324
const u32 state{ar};
325325

326326
usz seg_count = 0;
327-
ar.deserialize_vle(seg_count);
327+
ar.deserialize_vle<9>(seg_count);
328328

329329
shared_ptr<lv2_prx> prx;
330330

rpcs3/util/serialization.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,12 @@ namespace utils
206206
return true;
207207
}
208208

209-
template <typename T> requires Integral<T>
209+
template <uint MaxBits = 0, typename T> requires Integral<T> && (MaxBits <= sizeof(T) * 8)
210210
bool deserialize_vle(T& value)
211211
{
212212
using unsigned_type = std::make_unsigned_t<T>;
213213
unsigned_type result{};
214-
constexpr u32 bit_width = sizeof(T) * 8;
214+
constexpr u32 bit_width = MaxBits ? sizeof(T) * 8 : MaxBits;
215215
value = {};
216216

217217
for (u32 i = 0;; i += 7)
@@ -306,7 +306,7 @@ namespace utils
306306
}
307307

308308
usz size = 0;
309-
if (!deserialize_vle(size))
309+
if (!deserialize_vle<28>(size))
310310
{
311311
return false;
312312
}
@@ -423,7 +423,7 @@ namespace utils
423423
}
424424

425425
usz size = 0;
426-
if (!deserialize_vle(size))
426+
if (!deserialize_vle<28>(size))
427427
{
428428
return false;
429429
}

0 commit comments

Comments
 (0)