From d08c7a9b963ad3fd41d2c80f58b0f51296b3c992 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Tue, 19 Dec 2023 01:13:59 +0100 Subject: [PATCH] sceNpDrm: improve error handling of rap files --- rpcs3/Emu/Cell/Modules/sceNp.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/sceNp.cpp b/rpcs3/Emu/Cell/Modules/sceNp.cpp index 7b53f751d5..599adf1520 100644 --- a/rpcs3/Emu/Cell/Modules/sceNp.cpp +++ b/rpcs3/Emu/Cell/Modules/sceNp.cpp @@ -531,13 +531,19 @@ error_code npDrmIsAvailable(vm::cptr k_licensee_addr, vm::cptr drm_pat { const std::string rap_file = rpcs3::utils::get_rap_file_path(npd.content_id); - if (fs::file rap_fd{rap_file}; rap_fd && rap_fd.size() >= sizeof(u128)) + if (fs::file rap_fd{rap_file}) { + if (rap_fd.size() < sizeof(u128)) + { + sceNp.error("npDrmIsAvailable(): Rap file too small: '%s' (%d bytes)", rap_file, rap_fd.size()); + return {SCE_NP_DRM_ERROR_BAD_FORMAT, enc_drm_path}; + } + npdrmkeys.install_decryption_key(GetEdatRifKeyFromRapFile(rap_fd)); } else { - sceNp.error(u8"npDrmIsAvailable(): Rap file not found: ā€œ%sā€", rap_file); + sceNp.error("npDrmIsAvailable(): Rap file not found: '%s' (%s)", rap_file, fs::g_tls_error); return {SCE_NP_DRM_ERROR_LICENSE_NOT_FOUND, enc_drm_path}; } }