Skip to content

Commit a34aaac

Browse files
authored
Merge branch 'master' into curler
2 parents 677e78d + 7be182e commit a34aaac

3 files changed

Lines changed: 25 additions & 13 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/Emu/NP/clans_client.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
LOG_CHANNEL(clan_log, "clans");
3232

33-
3433
const char* REQ_TYPE_FUNC = "func";
3534
const char* REQ_TYPE_SEC = "sec";
3635

@@ -128,6 +127,11 @@ void fmt_class_string<clan::ClanRequestAction>::format(std::string& out, u64 arg
128127

129128
namespace clan
130129
{
130+
constexpr size_t base64_size(size_t size)
131+
{
132+
return (size + 2) / 3 * 4 + 1;
133+
}
134+
131135
size_t clans_client::curl_write_callback(void* data, size_t size, size_t nmemb, void* clientp)
132136
{
133137
const size_t realsize = size * nmemb;
@@ -341,11 +345,16 @@ namespace clan
341345
return "";
342346
}
343347

344-
std::vector<byte> ticket_bytes(1024);
345-
uint32_t ticket_size = UINT32_MAX;
348+
std::vector<byte> ticket_bytes(base64_size(clan_ticket.size()));
349+
uint32_t encoded_ticket_size = ::size32(ticket_bytes);
350+
351+
if (Base64_Encode_NoNl(clan_ticket.data(), ::size32(clan_ticket), ticket_bytes.data(), &encoded_ticket_size) != 0)
352+
{
353+
clan_log.error("Failed to encode clan ticket to base64");
354+
return "";
355+
}
346356

347-
Base64_Encode_NoNl(clan_ticket.data(), static_cast<u32>(clan_ticket.size()), ticket_bytes.data(), &ticket_size);
348-
const std::string ticket_str = std::string(reinterpret_cast<char*>(ticket_bytes.data()), ticket_size);
357+
const std::string ticket_str = std::string(reinterpret_cast<char*>(ticket_bytes.data()), encoded_ticket_size);
349358

350359
return ticket_str;
351360
}
@@ -923,11 +932,14 @@ namespace clan
923932

924933
pugi::xml_node status = clan.append_child("bin-attr1"sv);
925934

935+
const u32 bin_data_size = static_cast<u32>(info.binData1Size);
936+
if (bin_data_size > sizeof(info.binAttr1))
937+
return SCE_NP_CLANS_ERROR_INVALID_ARGUMENT;
938+
926939
byte bin_attr_1[SCE_NP_CLANS_MEMBER_BINARY_ATTRIBUTE1_MAX_SIZE * 2 + 1] = {0};
927-
uint32_t bin_attr_1_size = UINT32_MAX;
928-
Base64_Encode_NoNl(info.binAttr1, info.binData1Size, bin_attr_1, &bin_attr_1_size);
940+
uint32_t bin_attr_1_size = sizeof(bin_attr_1);
929941

930-
if (bin_attr_1_size == UINT32_MAX)
942+
if (Base64_Encode_NoNl(info.binAttr1, bin_data_size, bin_attr_1, &bin_attr_1_size) != 0)
931943
return SCE_NP_CLANS_ERROR_INVALID_ARGUMENT;
932944

933945
// `reinterpret_cast` used to let the compiler select the correct overload of `set`

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)