Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions rpcs3/util/serialization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ namespace utils
template <typename T> requires Integral<T>
bool deserialize_vle(T& value)
{
using unsigned_type = std::make_unsigned_t<T>;
unsigned_type result{};
constexpr u32 bit_width = sizeof(T) * 8;
value = {};

for (u32 i = 0;; i += 7)
Expand All @@ -220,12 +223,25 @@ namespace utils
return false;
}

value |= static_cast<T>(byte_data % 0x80) << i;
const unsigned_type payload = static_cast<unsigned_type>(byte_data % 0x80);

if (i >= bit_width || payload > (~unsigned_type{} >> i))
{
return false;
}

result |= payload << i;

if (!(byte_data & 0x80))
{
value = static_cast<T>(result);
break;
}

if (i > bit_width - 7)
{
return false;
}
}

return true;
Expand Down Expand Up @@ -297,7 +313,14 @@ namespace utils

if constexpr (Bitcopy<typename T::value_type>)
{
if (!raw_serialize([&](){ obj.resize(size); return obj.data(); }, sizeof(obj[0]) * size))
if (size > static_cast<usz>(umax) / sizeof(obj[0]))
{
return false;
}

const usz data_size = sizeof(obj[0]) * size;

if (!raw_serialize([&](){ obj.resize(size); return obj.data(); }, data_size))
{
obj.clear();
return false;
Expand Down
Loading