Skip to content

Commit ae59ed4

Browse files
authored
Merge branch 'RPCS3:master' into startup-fix
2 parents 53e81cd + 5ab2398 commit ae59ed4

10 files changed

Lines changed: 84 additions & 27 deletions

File tree

3rdparty/libsdl-org/SDL

Submodule SDL updated 67 files

rpcs3/Crypto/unself.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,20 @@ bool SCEDecrypter::LoadMetadata(const u8 erk[32], const u8 riv[16])
627627
{
628628
aes_context aes;
629629
std::vector<u8> metadata_info(sizeof(meta_info));
630-
std::vector<u8> metadata_headers(sce_hdr.se_hsize - (sizeof(sce_hdr) + sce_hdr.se_meta + sizeof(meta_info)));
630+
constexpr usz sizeof_meta_and_header = sizeof(meta_info) + sizeof(sce_hdr);
631+
const usz metadata_offset = static_cast<usz>(sce_hdr.se_meta);
632+
633+
if (metadata_offset > usz{umax} - sizeof_meta_and_header ||
634+
sce_hdr.se_hsize < sizeof_meta_and_header + metadata_offset ||
635+
sce_hdr.se_hsize - (sizeof_meta_and_header + metadata_offset) < sizeof(meta_hdr) ||
636+
sce_hdr.se_hsize > sce_f.size())
637+
{
638+
self_log.error("Invalid SCE metadata header size!");
639+
return false;
640+
}
641+
642+
const usz metadata_headers_offset = sizeof_meta_and_header + metadata_offset;
643+
std::vector<u8> metadata_headers(sce_hdr.se_hsize - metadata_headers_offset);
631644

632645
// Locate and read the encrypted metadata info.
633646
sce_f.seek(sce_hdr.se_meta + sizeof(sce_hdr));
@@ -1123,7 +1136,20 @@ bool SELFDecrypter::LoadMetadata(const u8* klic_key)
11231136
{
11241137
aes_context aes;
11251138
std::vector<u8> metadata_info(sizeof(meta_info));
1126-
std::vector<u8> metadata_headers(sce_hdr.se_hsize - (sizeof(sce_hdr) + sce_hdr.se_meta + sizeof(meta_info)));
1139+
constexpr usz sizeof_meta_and_header = sizeof(meta_info) + sizeof(sce_hdr);
1140+
const usz metadata_offset = static_cast<usz>(sce_hdr.se_meta);
1141+
1142+
if (metadata_offset > usz{umax} - sizeof_meta_and_header ||
1143+
sce_hdr.se_hsize < sizeof_meta_and_header + metadata_offset ||
1144+
sce_hdr.se_hsize - (sizeof_meta_and_header + metadata_offset) < sizeof(meta_hdr) ||
1145+
sce_hdr.se_hsize > self_f.size())
1146+
{
1147+
self_log.error("Invalid SELF metadata header size!");
1148+
return false;
1149+
}
1150+
1151+
const usz metadata_headers_offset = sizeof_meta_and_header + metadata_offset;
1152+
std::vector<u8> metadata_headers(sce_hdr.se_hsize - metadata_headers_offset);
11271153

11281154
// Locate and read the encrypted metadata info.
11291155
self_f.seek(sce_hdr.se_meta + sizeof(sce_hdr));

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/RSX/Overlays/BigPicture/overlay_big_picture.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ namespace rsx
8484
break;
8585
}
8686

87+
const bool main_menu_is_current_page = m_main_menu.is_current_page;
8788
const page_navigation navigation = m_main_menu.handle_button_press(button_press, is_auto_repeat, m_auto_repeat_ms_interval);
8889

8990
switch (navigation)
@@ -110,6 +111,12 @@ namespace rsx
110111
}
111112
case page_navigation::exit:
112113
{
114+
// Don't exit if circle was pressed in the main menu
115+
if (main_menu_is_current_page && button_press == pad_button::circle)
116+
{
117+
break;
118+
}
119+
113120
// Don't call close() synchronously from the input thread - just like the pause menu's own
114121
// "Exit Game", tearing down the shell on the main thread takes this dialog down as a side effect.
115122
g_big_picture_mode_active = false;

rpcs3/Emu/RSX/Overlays/BigPicture/overlay_big_picture_game_grid.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ namespace rsx
161161

162162
void big_picture_game_grid::finish_reload(std::vector<std::unique_ptr<big_picture_game_tile>>&& tiles)
163163
{
164-
std::lock_guard lock(m_reload_mutex);
164+
std::lock_guard lock(m_mutex);
165165

166166
if (thread_ctrl::state() == thread_state::aborting)
167167
{
@@ -280,6 +280,8 @@ namespace rsx
280280

281281
page_navigation big_picture_game_grid::handle_button_press(pad_button button_press, bool is_auto_repeat, u64 auto_repeat_interval_ms)
282282
{
283+
std::lock_guard lock(m_mutex);
284+
283285
if (m_loading) return page_navigation::stay;
284286

285287
const bool do_play_sound = !is_auto_repeat || auto_repeat_interval_ms >= user_interface::m_auto_repeat_ms_interval_default;
@@ -322,12 +324,8 @@ namespace rsx
322324
if (button_press == pad_button::circle)
323325
{
324326
play_sound(sound_effect::cancel);
325-
if (parent)
326-
{
327-
set_current_page(parent);
328-
return page_navigation::back;
329-
}
330-
return page_navigation::exit;
327+
set_current_page(ensure(parent));
328+
return page_navigation::back;
331329
}
332330

333331
return page_navigation::stay;
@@ -372,12 +370,8 @@ namespace rsx
372370
return page_navigation::stay;
373371
case pad_button::circle:
374372
play_sound(sound_effect::cancel);
375-
if (parent)
376-
{
377-
set_current_page(parent);
378-
return page_navigation::back;
379-
}
380-
return page_navigation::exit;
373+
set_current_page(ensure(parent));
374+
return page_navigation::back;
381375
default:
382376
return page_navigation::stay;
383377
}
@@ -392,7 +386,7 @@ namespace rsx
392386

393387
compiled_resource& big_picture_game_grid::get_compiled()
394388
{
395-
std::lock_guard lock(m_reload_mutex);
389+
std::lock_guard lock(m_mutex);
396390

397391
if (!m_highlight->is_compiled() ||
398392
(!m_tiles.empty() && m_grid && !m_grid->is_compiled()) ||

rpcs3/Emu/RSX/Overlays/BigPicture/overlay_big_picture_game_grid.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ namespace rsx
5252
static constexpr u16 m_columns = 5;
5353
static constexpr u16 m_tile_size = 200;
5454

55-
std::mutex m_reload_mutex;
55+
std::mutex m_mutex;
5656
std::unique_ptr<named_thread<std::function<void()>>> m_game_enumeration_thread;
5757

5858
game_enumeration<big_picture_game_info> m_game_enumeration;

rpcs3/Emu/RSX/Overlays/overlay_manager.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "stdafx.h"
22
#include "overlay_manager.h"
3-
#include "Emu/System.h"
43
#include <util/asm.hpp>
54

65
namespace rsx

rpcs3/Emu/System.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,8 @@ bool Emulator::BootRsxCapture(const std::string& path)
943943
GetCallbacks().on_ready();
944944

945945
GetCallbacks().init_gs_render(nullptr);
946+
GetCallbacks().init_kb_handler();
947+
GetCallbacks().init_mouse_handler();
946948
GetCallbacks().init_pad_handler("");
947949

948950
GetCallbacks().on_run(false);
@@ -1001,6 +1003,8 @@ bool Emulator::BootBigPictureMode()
10011003
GetCallbacks().on_ready();
10021004

10031005
GetCallbacks().init_gs_render(nullptr);
1006+
GetCallbacks().init_kb_handler();
1007+
GetCallbacks().init_mouse_handler();
10041008
GetCallbacks().init_pad_handler("");
10051009

10061010
GetCallbacks().on_run(false);

rpcs3/Loader/ELF.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,9 @@ class elf_object
373373
// Try to find it in phdr data instead of allocating new section
374374
p_index++;
375375

376-
if (hdr.p_offset <= shdr.sh_offset && shdr.sh_offset + shdr.sh_size <= hdr.p_offset + hdr.p_filesz)
376+
if (hdr.p_offset <= shdr.sh_offset &&
377+
shdr.sh_size <= hdr.p_filesz &&
378+
shdr.sh_offset - hdr.p_offset <= hdr.p_filesz - shdr.sh_size)
377379
{
378380
const auto& prog = ::at32(progs, p_index);
379381
shdrs.back().bin_view = {prog.bin.data() + shdr.sh_offset - hdr.p_offset, shdr.sh_size};
@@ -469,7 +471,9 @@ class elf_object
469471
p_index++;
470472

471473
// Rely on previous sh_offset value!
472-
if (hdr.p_offset <= shdr.sh_offset && shdr.sh_offset + shdr.sh_size - 1 <= hdr.p_offset + hdr.p_filesz - 1)
474+
if (hdr.p_offset <= shdr.sh_offset &&
475+
shdr.sh_size <= hdr.p_filesz &&
476+
shdr.sh_offset - hdr.p_offset <= hdr.p_filesz - shdr.sh_size)
473477
{
474478
out.sh_offset = ::narrow<sz_t>(data_base + static_cast<usz>(shdr.sh_offset - hdr.p_offset));
475479
result = true;

rpcs3/util/serialization.hpp

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +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
{
212+
using unsigned_type = std::make_unsigned_t<T>;
213+
unsigned_type result{};
214+
constexpr u32 bit_width = MaxBits ? sizeof(T) * 8 : MaxBits;
212215
value = {};
213216

214217
for (u32 i = 0;; i += 7)
@@ -220,12 +223,25 @@ namespace utils
220223
return false;
221224
}
222225

223-
value |= static_cast<T>(byte_data % 0x80) << i;
226+
const unsigned_type payload = static_cast<unsigned_type>(byte_data % 0x80);
227+
228+
if (i >= bit_width || payload > (~unsigned_type{} >> i))
229+
{
230+
return false;
231+
}
232+
233+
result |= payload << i;
224234

225235
if (!(byte_data & 0x80))
226236
{
237+
value = static_cast<T>(result);
227238
break;
228239
}
240+
241+
if (i > bit_width - 7)
242+
{
243+
return false;
244+
}
229245
}
230246

231247
return true;
@@ -290,14 +306,21 @@ namespace utils
290306
}
291307

292308
usz size = 0;
293-
if (!deserialize_vle(size))
309+
if (!deserialize_vle<28>(size))
294310
{
295311
return false;
296312
}
297313

298314
if constexpr (Bitcopy<typename T::value_type>)
299315
{
300-
if (!raw_serialize([&](){ obj.resize(size); return obj.data(); }, sizeof(obj[0]) * size))
316+
if (size > static_cast<usz>(umax) / sizeof(obj[0]))
317+
{
318+
return false;
319+
}
320+
321+
const usz data_size = sizeof(obj[0]) * size;
322+
323+
if (!raw_serialize([&](){ obj.resize(size); return obj.data(); }, data_size))
301324
{
302325
obj.clear();
303326
return false;
@@ -400,7 +423,7 @@ namespace utils
400423
}
401424

402425
usz size = 0;
403-
if (!deserialize_vle(size))
426+
if (!deserialize_vle<28>(size))
404427
{
405428
return false;
406429
}

0 commit comments

Comments
 (0)