From a03abd15e93cee78cf3b70f8fabdec72ef4476c1 Mon Sep 17 00:00:00 2001 From: MaranBr Date: Mon, 8 Sep 2025 14:06:05 -0400 Subject: [PATCH 01/15] Improve integrity check validation code --- ...ssystem_integrity_verification_storage.cpp | 43 ++++++------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp b/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp index 046571e9ef..90746bbeb8 100644 --- a/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp +++ b/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp @@ -4,8 +4,8 @@ // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later -#include "core/file_sys/fssystem/fssystem_integrity_verification_storage.h" #include "common/alignment.h" +#include "core/file_sys/fssystem/fssystem_integrity_verification_storage.h" namespace FileSys { @@ -15,19 +15,17 @@ constexpr inline u32 ILog2(u32 val) return static_cast((sizeof(u32) * 8) - 1 - std::countl_zero(val)); } -void IntegrityVerificationStorage::Initialize(VirtualFile hs, - VirtualFile ds, - s64 verif_block_size, - s64 upper_layer_verif_block_size, - bool is_real_data) -{ - // Validate preconditions. - ASSERT(verif_block_size >= HashSize); +void IntegrityVerificationStorage::Initialize(VirtualFile hs, VirtualFile ds, s64 verif_block_size, + s64 upper_layer_verif_block_size, bool is_real_data) { // Set storages. m_hash_storage = hs; m_data_storage = ds; + // Validate preconditions. + ASSERT(verif_block_size >= HashSize); + ASSERT(m_data_storage != null); + // Set verification block sizes. m_verification_block_size = verif_block_size; m_verification_block_order = ILog2(static_cast(verif_block_size)); @@ -40,28 +38,20 @@ void IntegrityVerificationStorage::Initialize(VirtualFile hs, ASSERT(m_upper_layer_verification_block_size == 1ll << m_upper_layer_verification_block_order); // Validate sizes. - if (m_data_storage != nullptr) { - s64 hash_size = m_hash_storage->GetSize(); - s64 data_size = m_data_storage->GetSize(); - ASSERT(((hash_size / HashSize) * m_verification_block_size) >= data_size); - } else { - LOG_ERROR(Loader, - "Failed to initialize integrity verification store. Game, update, or DLC may not " - "work."); - } + s64 hash_size = m_hash_storage->GetSize(); + s64 data_size = m_data_storage->GetSize(); + ASSERT(((hash_size / HashSize) * m_verification_block_size) >= data_size); // Set data. m_is_real_data = is_real_data; } -void IntegrityVerificationStorage::Finalize() -{ +void IntegrityVerificationStorage::Finalize() { m_hash_storage = VirtualFile(); m_data_storage = VirtualFile(); } -size_t IntegrityVerificationStorage::Read(u8* buffer, size_t size, size_t offset) const -{ +size_t IntegrityVerificationStorage::Read(u8* buffer, size_t size, size_t offset) const { // Succeed if zero size. if (size == 0) { return size; @@ -69,14 +59,9 @@ size_t IntegrityVerificationStorage::Read(u8* buffer, size_t size, size_t offset // Validate arguments. ASSERT(buffer != nullptr); + ASSERT(m_data_storage != nullptr); - if (m_data_storage == nullptr) { - LOG_ERROR(Loader, - "Integrity verification store failed read operation. Game, update or DLC may not " - "work."); - return 0; - } - + // Validate the offset. s64 data_size = m_data_storage->GetSize(); ASSERT(offset <= static_cast(data_size)); -- 2.39.5 From 9480c0d22d3ead3e1c8833a849f5cfe858a53c90 Mon Sep 17 00:00:00 2001 From: MaranBr Date: Mon, 8 Sep 2025 14:15:49 -0400 Subject: [PATCH 02/15] Organize some things --- .../fssystem_integrity_verification_storage.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp b/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp index 90746bbeb8..be5ab00c71 100644 --- a/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp +++ b/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp @@ -9,15 +9,13 @@ namespace FileSys { -constexpr inline u32 ILog2(u32 val) -{ +constexpr inline u32 ILog2(u32 val) { ASSERT(val > 0); return static_cast((sizeof(u32) * 8) - 1 - std::countl_zero(val)); } void IntegrityVerificationStorage::Initialize(VirtualFile hs, VirtualFile ds, s64 verif_block_size, s64 upper_layer_verif_block_size, bool is_real_data) { - // Set storages. m_hash_storage = hs; m_data_storage = ds; @@ -38,9 +36,11 @@ void IntegrityVerificationStorage::Initialize(VirtualFile hs, VirtualFile ds, s6 ASSERT(m_upper_layer_verification_block_size == 1ll << m_upper_layer_verification_block_order); // Validate sizes. - s64 hash_size = m_hash_storage->GetSize(); - s64 data_size = m_data_storage->GetSize(); - ASSERT(((hash_size / HashSize) * m_verification_block_size) >= data_size); + { + s64 hash_size = m_hash_storage->GetSize(); + s64 data_size = m_data_storage->GetSize(); + ASSERT(((hash_size / HashSize) * m_verification_block_size) >= data_size); + } // Set data. m_is_real_data = is_real_data; @@ -89,8 +89,7 @@ size_t IntegrityVerificationStorage::Read(u8* buffer, size_t size, size_t offset return m_data_storage->Read(buffer, read_size, offset); } -size_t IntegrityVerificationStorage::GetSize() const -{ +size_t IntegrityVerificationStorage::GetSize() const { return m_data_storage->GetSize(); } -- 2.39.5 From 8826a619f8585d4098236e8cd50a2afc7ee9f25b Mon Sep 17 00:00:00 2001 From: MaranBr Date: Mon, 8 Sep 2025 14:32:25 -0400 Subject: [PATCH 03/15] Fix build --- .../fssystem/fssystem_integrity_verification_storage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp b/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp index be5ab00c71..5cfda1b699 100644 --- a/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp +++ b/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp @@ -22,7 +22,7 @@ void IntegrityVerificationStorage::Initialize(VirtualFile hs, VirtualFile ds, s6 // Validate preconditions. ASSERT(verif_block_size >= HashSize); - ASSERT(m_data_storage != null); + ASSERT(m_data_storage != nullptr); // Set verification block sizes. m_verification_block_size = verif_block_size; -- 2.39.5 From bc060aa1f86587949a933715515fc29ac123e390 Mon Sep 17 00:00:00 2001 From: MaranBr Date: Mon, 8 Sep 2025 15:53:44 -0400 Subject: [PATCH 04/15] Restore old behavior --- .../fssystem/fssystem_integrity_verification_storage.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp b/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp index 5cfda1b699..725f097b57 100644 --- a/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp +++ b/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp @@ -16,14 +16,13 @@ constexpr inline u32 ILog2(u32 val) { void IntegrityVerificationStorage::Initialize(VirtualFile hs, VirtualFile ds, s64 verif_block_size, s64 upper_layer_verif_block_size, bool is_real_data) { + // Validate preconditions. + ASSERT(verif_block_size >= HashSize); + // Set storages. m_hash_storage = hs; m_data_storage = ds; - // Validate preconditions. - ASSERT(verif_block_size >= HashSize); - ASSERT(m_data_storage != nullptr); - // Set verification block sizes. m_verification_block_size = verif_block_size; m_verification_block_order = ILog2(static_cast(verif_block_size)); @@ -59,7 +58,6 @@ size_t IntegrityVerificationStorage::Read(u8* buffer, size_t size, size_t offset // Validate arguments. ASSERT(buffer != nullptr); - ASSERT(m_data_storage != nullptr); // Validate the offset. s64 data_size = m_data_storage->GetSize(); -- 2.39.5 From 856b1ab5b8844ead2853a0d4bf1371a1f05a2aa2 Mon Sep 17 00:00:00 2001 From: MaranBr Date: Tue, 9 Sep 2025 10:48:11 -0400 Subject: [PATCH 05/15] Avoid crashes when installing new updates --- src/core/file_sys/content_archive.cpp | 4 ++-- .../file_sys/fssystem/fssystem_nca_file_system_driver.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/file_sys/content_archive.cpp b/src/core/file_sys/content_archive.cpp index 6652523589..d090fc0146 100644 --- a/src/core/file_sys/content_archive.cpp +++ b/src/core/file_sys/content_archive.cpp @@ -85,12 +85,12 @@ NCA::NCA(VirtualFile file_, const NCA* base_nca) for (s32 i = 0; i < fs_count; i++) { NcaFsHeaderReader header_reader; const Result rc = fs.OpenStorage(&filesystems[i], &header_reader, i); - if (R_FAILED(rc)) { + /*if (R_FAILED(rc)) { LOG_ERROR(Loader, "File reader errored out during read of section {}: {:#x}", i, rc.GetInnerValue()); status = Loader::ResultStatus::ErrorBadNCAHeader; return; - } + }*/ if (header_reader.GetFsType() == NcaFsHeader::FsType::RomFs) { files.push_back(filesystems[i]); diff --git a/src/core/file_sys/fssystem/fssystem_nca_file_system_driver.cpp b/src/core/file_sys/fssystem/fssystem_nca_file_system_driver.cpp index 1bc7039318..7a6c3696e0 100644 --- a/src/core/file_sys/fssystem/fssystem_nca_file_system_driver.cpp +++ b/src/core/file_sys/fssystem/fssystem_nca_file_system_driver.cpp @@ -1051,7 +1051,7 @@ Result NcaFileSystemDriver::CreatePatchMetaStorage( ASSERT(out_aes_ctr_ex_meta != nullptr); ASSERT(out_indirect_meta != nullptr); ASSERT(base_storage != nullptr); - ASSERT(patch_info.HasAesCtrExTable()); + //ASSERT(patch_info.HasAesCtrExTable()); ASSERT(patch_info.HasIndirectTable()); ASSERT(Common::IsAligned(patch_info.aes_ctr_ex_size, NcaHeader::XtsBlockSize)); @@ -1334,8 +1334,8 @@ Result NcaFileSystemDriver::CreateIntegrityVerificationStorageImpl( R_UNLESS(last_layer_info_offset + layer_info.size <= layer_info_offset, ResultRomNcaInvalidIntegrityLayerInfoOffset); } - storage_info.SetDataStorage(std::make_shared( - std::move(base_storage), layer_info.size, last_layer_info_offset)); + storage_info[level_hash_info.max_layers - 1] = std::make_shared( + std::move(base_storage), layer_info.size, last_layer_info_offset); // Make the integrity romfs storage. auto integrity_storage = std::make_shared(); -- 2.39.5 From 64066e2eb9173a5a6ae39fbc6790cb226699cfaa Mon Sep 17 00:00:00 2001 From: MaranBr Date: Tue, 9 Sep 2025 11:17:04 -0400 Subject: [PATCH 06/15] Fix build --- src/core/file_sys/content_archive.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/file_sys/content_archive.cpp b/src/core/file_sys/content_archive.cpp index d090fc0146..d762751c22 100644 --- a/src/core/file_sys/content_archive.cpp +++ b/src/core/file_sys/content_archive.cpp @@ -84,8 +84,9 @@ NCA::NCA(VirtualFile file_, const NCA* base_nca) std::vector filesystems(fs_count); for (s32 i = 0; i < fs_count; i++) { NcaFsHeaderReader header_reader; - const Result rc = fs.OpenStorage(&filesystems[i], &header_reader, i); - /*if (R_FAILED(rc)) { + fs.OpenStorage(&filesystems[i], &header_reader, i); + /*const Result rc = fs.OpenStorage(&filesystems[i], &header_reader, i); + if (R_FAILED(rc)) { LOG_ERROR(Loader, "File reader errored out during read of section {}: {:#x}", i, rc.GetInnerValue()); status = Loader::ResultStatus::ErrorBadNCAHeader; -- 2.39.5 From 0522fe79ff2ce5202134c770c0a37aefe666cb8e Mon Sep 17 00:00:00 2001 From: MaranBr Date: Tue, 9 Sep 2025 14:22:09 -0400 Subject: [PATCH 07/15] Adjust some things --- src/core/file_sys/content_archive.cpp | 7 +++---- .../file_sys/fssystem/fssystem_nca_file_system_driver.cpp | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/core/file_sys/content_archive.cpp b/src/core/file_sys/content_archive.cpp index d762751c22..d0765315b2 100644 --- a/src/core/file_sys/content_archive.cpp +++ b/src/core/file_sys/content_archive.cpp @@ -84,14 +84,13 @@ NCA::NCA(VirtualFile file_, const NCA* base_nca) std::vector filesystems(fs_count); for (s32 i = 0; i < fs_count; i++) { NcaFsHeaderReader header_reader; - fs.OpenStorage(&filesystems[i], &header_reader, i); - /*const Result rc = fs.OpenStorage(&filesystems[i], &header_reader, i); + const Result rc = fs.OpenStorage(&filesystems[i], &header_reader, i); if (R_FAILED(rc)) { - LOG_ERROR(Loader, "File reader errored out during read of section {}: {:#x}", i, + LOG_DEBUG(Loader, "File reader errored out during read of section {}: {:#x}", i, rc.GetInnerValue()); status = Loader::ResultStatus::ErrorBadNCAHeader; return; - }*/ + } if (header_reader.GetFsType() == NcaFsHeader::FsType::RomFs) { files.push_back(filesystems[i]); diff --git a/src/core/file_sys/fssystem/fssystem_nca_file_system_driver.cpp b/src/core/file_sys/fssystem/fssystem_nca_file_system_driver.cpp index 7a6c3696e0..4cfa5c58f8 100644 --- a/src/core/file_sys/fssystem/fssystem_nca_file_system_driver.cpp +++ b/src/core/file_sys/fssystem/fssystem_nca_file_system_driver.cpp @@ -1052,7 +1052,7 @@ Result NcaFileSystemDriver::CreatePatchMetaStorage( ASSERT(out_indirect_meta != nullptr); ASSERT(base_storage != nullptr); //ASSERT(patch_info.HasAesCtrExTable()); - ASSERT(patch_info.HasIndirectTable()); + //ASSERT(patch_info.HasIndirectTable()); ASSERT(Common::IsAligned(patch_info.aes_ctr_ex_size, NcaHeader::XtsBlockSize)); // Validate patch info extents. -- 2.39.5 From fc6ada7e785cf3dcf2d32c1ed8290cd492d86086 Mon Sep 17 00:00:00 2001 From: MaranBr Date: Mon, 8 Sep 2025 14:06:05 -0400 Subject: [PATCH 08/15] Improve integrity check validation code --- ...ssystem_integrity_verification_storage.cpp | 43 ++++++------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp b/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp index 57cdc19248..345cad5fc4 100644 --- a/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp +++ b/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp @@ -4,8 +4,8 @@ // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later -#include "core/file_sys/fssystem/fssystem_integrity_verification_storage.h" #include "common/alignment.h" +#include "core/file_sys/fssystem/fssystem_integrity_verification_storage.h" namespace FileSys { @@ -15,19 +15,17 @@ constexpr inline u32 ILog2(u32 val) return static_cast((sizeof(u32) * 8) - 1 - std::countl_zero(val)); } -void IntegrityVerificationStorage::Initialize(VirtualFile hs, - VirtualFile ds, - s64 verif_block_size, - s64 upper_layer_verif_block_size, - bool is_real_data) -{ - // Validate preconditions. - ASSERT(verif_block_size >= HashSize); +void IntegrityVerificationStorage::Initialize(VirtualFile hs, VirtualFile ds, s64 verif_block_size, + s64 upper_layer_verif_block_size, bool is_real_data) { // Set storages. m_hash_storage = hs; m_data_storage = ds; + // Validate preconditions. + ASSERT(verif_block_size >= HashSize); + ASSERT(m_data_storage != null); + // Set verification block sizes. m_verification_block_size = verif_block_size; m_verification_block_order = ILog2(static_cast(verif_block_size)); @@ -40,28 +38,20 @@ void IntegrityVerificationStorage::Initialize(VirtualFile hs, ASSERT(m_upper_layer_verification_block_size == 1ll << m_upper_layer_verification_block_order); // Validate sizes. - if (m_data_storage != nullptr) { - s64 hash_size = m_hash_storage->GetSize(); - s64 data_size = m_data_storage->GetSize(); - ASSERT(((hash_size / HashSize) * m_verification_block_size) >= data_size); - } else { - LOG_ERROR(Loader, - "Failed to initialize integrity verification store. Game, update, or DLC may not " - "work."); - } + s64 hash_size = m_hash_storage->GetSize(); + s64 data_size = m_data_storage->GetSize(); + ASSERT(((hash_size / HashSize) * m_verification_block_size) >= data_size); // Set data. m_is_real_data = is_real_data; } -void IntegrityVerificationStorage::Finalize() -{ +void IntegrityVerificationStorage::Finalize() { m_hash_storage = VirtualFile(); m_data_storage = VirtualFile(); } -size_t IntegrityVerificationStorage::Read(u8* buffer, size_t size, size_t offset) const -{ +size_t IntegrityVerificationStorage::Read(u8* buffer, size_t size, size_t offset) const { // Succeed if zero size. if (size == 0) { return size; @@ -69,14 +59,9 @@ size_t IntegrityVerificationStorage::Read(u8* buffer, size_t size, size_t offset // Validate arguments. ASSERT(buffer != nullptr); + ASSERT(m_data_storage != nullptr); - if (m_data_storage == nullptr) { - LOG_ERROR(Loader, - "Integrity verification store failed read operation. Game, update or DLC may not " - "work."); - return 0; - } - + // Validate the offset. s64 data_size = m_data_storage->GetSize(); ASSERT(offset <= static_cast(data_size)); -- 2.39.5 From 951904b005b2fd418db7c8d393e2c23e9327751a Mon Sep 17 00:00:00 2001 From: MaranBr Date: Mon, 8 Sep 2025 14:15:49 -0400 Subject: [PATCH 09/15] Organize some things --- .../fssystem_integrity_verification_storage.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp b/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp index 345cad5fc4..c87148257a 100644 --- a/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp +++ b/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp @@ -9,15 +9,13 @@ namespace FileSys { -constexpr inline u32 ILog2(u32 val) -{ +constexpr inline u32 ILog2(u32 val) { ASSERT(val > 0); return static_cast((sizeof(u32) * 8) - 1 - std::countl_zero(val)); } void IntegrityVerificationStorage::Initialize(VirtualFile hs, VirtualFile ds, s64 verif_block_size, s64 upper_layer_verif_block_size, bool is_real_data) { - // Set storages. m_hash_storage = hs; m_data_storage = ds; @@ -38,9 +36,11 @@ void IntegrityVerificationStorage::Initialize(VirtualFile hs, VirtualFile ds, s6 ASSERT(m_upper_layer_verification_block_size == 1ll << m_upper_layer_verification_block_order); // Validate sizes. - s64 hash_size = m_hash_storage->GetSize(); - s64 data_size = m_data_storage->GetSize(); - ASSERT(((hash_size / HashSize) * m_verification_block_size) >= data_size); + { + s64 hash_size = m_hash_storage->GetSize(); + s64 data_size = m_data_storage->GetSize(); + ASSERT(((hash_size / HashSize) * m_verification_block_size) >= data_size); + } // Set data. m_is_real_data = is_real_data; @@ -89,8 +89,7 @@ size_t IntegrityVerificationStorage::Read(u8* buffer, size_t size, size_t offset return m_data_storage->Read(buffer, read_size, offset); } -size_t IntegrityVerificationStorage::GetSize() const -{ +size_t IntegrityVerificationStorage::GetSize() const { return m_data_storage->GetSize(); } -- 2.39.5 From 100bd9d014b8a6601fe5abe3e00d912242e68c29 Mon Sep 17 00:00:00 2001 From: MaranBr Date: Mon, 8 Sep 2025 14:32:25 -0400 Subject: [PATCH 10/15] Fix build --- .../fssystem/fssystem_integrity_verification_storage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp b/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp index c87148257a..7de095d5f3 100644 --- a/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp +++ b/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp @@ -22,7 +22,7 @@ void IntegrityVerificationStorage::Initialize(VirtualFile hs, VirtualFile ds, s6 // Validate preconditions. ASSERT(verif_block_size >= HashSize); - ASSERT(m_data_storage != null); + ASSERT(m_data_storage != nullptr); // Set verification block sizes. m_verification_block_size = verif_block_size; -- 2.39.5 From 34ad2d2f3b5e1901b8203e3da52a8f303d41f6fe Mon Sep 17 00:00:00 2001 From: MaranBr Date: Mon, 8 Sep 2025 15:53:44 -0400 Subject: [PATCH 11/15] Restore old behavior --- .../fssystem/fssystem_integrity_verification_storage.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp b/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp index 7de095d5f3..c1bad3ec36 100644 --- a/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp +++ b/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp @@ -16,14 +16,13 @@ constexpr inline u32 ILog2(u32 val) { void IntegrityVerificationStorage::Initialize(VirtualFile hs, VirtualFile ds, s64 verif_block_size, s64 upper_layer_verif_block_size, bool is_real_data) { + // Validate preconditions. + ASSERT(verif_block_size >= HashSize); + // Set storages. m_hash_storage = hs; m_data_storage = ds; - // Validate preconditions. - ASSERT(verif_block_size >= HashSize); - ASSERT(m_data_storage != nullptr); - // Set verification block sizes. m_verification_block_size = verif_block_size; m_verification_block_order = ILog2(static_cast(verif_block_size)); @@ -59,7 +58,6 @@ size_t IntegrityVerificationStorage::Read(u8* buffer, size_t size, size_t offset // Validate arguments. ASSERT(buffer != nullptr); - ASSERT(m_data_storage != nullptr); // Validate the offset. s64 data_size = m_data_storage->GetSize(); -- 2.39.5 From d110d88d5625fe8c78b618bec8beaa7e36efd560 Mon Sep 17 00:00:00 2001 From: MaranBr Date: Tue, 9 Sep 2025 10:48:11 -0400 Subject: [PATCH 12/15] Avoid crashes when installing new updates --- src/core/file_sys/content_archive.cpp | 4 ++-- .../file_sys/fssystem/fssystem_nca_file_system_driver.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/file_sys/content_archive.cpp b/src/core/file_sys/content_archive.cpp index 6652523589..d090fc0146 100644 --- a/src/core/file_sys/content_archive.cpp +++ b/src/core/file_sys/content_archive.cpp @@ -85,12 +85,12 @@ NCA::NCA(VirtualFile file_, const NCA* base_nca) for (s32 i = 0; i < fs_count; i++) { NcaFsHeaderReader header_reader; const Result rc = fs.OpenStorage(&filesystems[i], &header_reader, i); - if (R_FAILED(rc)) { + /*if (R_FAILED(rc)) { LOG_ERROR(Loader, "File reader errored out during read of section {}: {:#x}", i, rc.GetInnerValue()); status = Loader::ResultStatus::ErrorBadNCAHeader; return; - } + }*/ if (header_reader.GetFsType() == NcaFsHeader::FsType::RomFs) { files.push_back(filesystems[i]); diff --git a/src/core/file_sys/fssystem/fssystem_nca_file_system_driver.cpp b/src/core/file_sys/fssystem/fssystem_nca_file_system_driver.cpp index 1bc7039318..7a6c3696e0 100644 --- a/src/core/file_sys/fssystem/fssystem_nca_file_system_driver.cpp +++ b/src/core/file_sys/fssystem/fssystem_nca_file_system_driver.cpp @@ -1051,7 +1051,7 @@ Result NcaFileSystemDriver::CreatePatchMetaStorage( ASSERT(out_aes_ctr_ex_meta != nullptr); ASSERT(out_indirect_meta != nullptr); ASSERT(base_storage != nullptr); - ASSERT(patch_info.HasAesCtrExTable()); + //ASSERT(patch_info.HasAesCtrExTable()); ASSERT(patch_info.HasIndirectTable()); ASSERT(Common::IsAligned(patch_info.aes_ctr_ex_size, NcaHeader::XtsBlockSize)); @@ -1334,8 +1334,8 @@ Result NcaFileSystemDriver::CreateIntegrityVerificationStorageImpl( R_UNLESS(last_layer_info_offset + layer_info.size <= layer_info_offset, ResultRomNcaInvalidIntegrityLayerInfoOffset); } - storage_info.SetDataStorage(std::make_shared( - std::move(base_storage), layer_info.size, last_layer_info_offset)); + storage_info[level_hash_info.max_layers - 1] = std::make_shared( + std::move(base_storage), layer_info.size, last_layer_info_offset); // Make the integrity romfs storage. auto integrity_storage = std::make_shared(); -- 2.39.5 From e6c2b1aeadfc09df58fb8a5016fb11c934362113 Mon Sep 17 00:00:00 2001 From: MaranBr Date: Tue, 9 Sep 2025 11:17:04 -0400 Subject: [PATCH 13/15] Fix build --- src/core/file_sys/content_archive.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/file_sys/content_archive.cpp b/src/core/file_sys/content_archive.cpp index d090fc0146..d762751c22 100644 --- a/src/core/file_sys/content_archive.cpp +++ b/src/core/file_sys/content_archive.cpp @@ -84,8 +84,9 @@ NCA::NCA(VirtualFile file_, const NCA* base_nca) std::vector filesystems(fs_count); for (s32 i = 0; i < fs_count; i++) { NcaFsHeaderReader header_reader; - const Result rc = fs.OpenStorage(&filesystems[i], &header_reader, i); - /*if (R_FAILED(rc)) { + fs.OpenStorage(&filesystems[i], &header_reader, i); + /*const Result rc = fs.OpenStorage(&filesystems[i], &header_reader, i); + if (R_FAILED(rc)) { LOG_ERROR(Loader, "File reader errored out during read of section {}: {:#x}", i, rc.GetInnerValue()); status = Loader::ResultStatus::ErrorBadNCAHeader; -- 2.39.5 From 45619919330ebc2028e6535a30836420fbf4f677 Mon Sep 17 00:00:00 2001 From: MaranBr Date: Tue, 9 Sep 2025 14:22:09 -0400 Subject: [PATCH 14/15] Adjust some things --- src/core/file_sys/content_archive.cpp | 7 +++---- .../file_sys/fssystem/fssystem_nca_file_system_driver.cpp | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/core/file_sys/content_archive.cpp b/src/core/file_sys/content_archive.cpp index d762751c22..d0765315b2 100644 --- a/src/core/file_sys/content_archive.cpp +++ b/src/core/file_sys/content_archive.cpp @@ -84,14 +84,13 @@ NCA::NCA(VirtualFile file_, const NCA* base_nca) std::vector filesystems(fs_count); for (s32 i = 0; i < fs_count; i++) { NcaFsHeaderReader header_reader; - fs.OpenStorage(&filesystems[i], &header_reader, i); - /*const Result rc = fs.OpenStorage(&filesystems[i], &header_reader, i); + const Result rc = fs.OpenStorage(&filesystems[i], &header_reader, i); if (R_FAILED(rc)) { - LOG_ERROR(Loader, "File reader errored out during read of section {}: {:#x}", i, + LOG_DEBUG(Loader, "File reader errored out during read of section {}: {:#x}", i, rc.GetInnerValue()); status = Loader::ResultStatus::ErrorBadNCAHeader; return; - }*/ + } if (header_reader.GetFsType() == NcaFsHeader::FsType::RomFs) { files.push_back(filesystems[i]); diff --git a/src/core/file_sys/fssystem/fssystem_nca_file_system_driver.cpp b/src/core/file_sys/fssystem/fssystem_nca_file_system_driver.cpp index 7a6c3696e0..4cfa5c58f8 100644 --- a/src/core/file_sys/fssystem/fssystem_nca_file_system_driver.cpp +++ b/src/core/file_sys/fssystem/fssystem_nca_file_system_driver.cpp @@ -1052,7 +1052,7 @@ Result NcaFileSystemDriver::CreatePatchMetaStorage( ASSERT(out_indirect_meta != nullptr); ASSERT(base_storage != nullptr); //ASSERT(patch_info.HasAesCtrExTable()); - ASSERT(patch_info.HasIndirectTable()); + //ASSERT(patch_info.HasIndirectTable()); ASSERT(Common::IsAligned(patch_info.aes_ctr_ex_size, NcaHeader::XtsBlockSize)); // Validate patch info extents. -- 2.39.5 From a5c6860d3734f4d4044f86cb96f462d57eb67784 Mon Sep 17 00:00:00 2001 From: MaranBr Date: Tue, 9 Sep 2025 15:00:40 -0400 Subject: [PATCH 15/15] Ready to merge --- src/core/file_sys/content_archive.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/core/file_sys/content_archive.cpp b/src/core/file_sys/content_archive.cpp index d0765315b2..b961cdb096 100644 --- a/src/core/file_sys/content_archive.cpp +++ b/src/core/file_sys/content_archive.cpp @@ -34,12 +34,9 @@ NCA::NCA(VirtualFile file_, const NCA* base_nca) } reader = std::make_shared(); - if (Result rc = - reader->Initialize(file, GetCryptoConfiguration(), GetNcaCompressionConfiguration()); - R_FAILED(rc)) { + if (Result rc = reader->Initialize(file, GetCryptoConfiguration(), GetNcaCompressionConfiguration()); R_FAILED(rc)) { if (rc != ResultInvalidNcaSignature) { - LOG_ERROR(Loader, "File reader errored out during header read: {:#x}", - rc.GetInnerValue()); + LOG_ERROR(Loader, "File reader errored out during header read: {:#x}", rc.GetInnerValue()); } status = Loader::ResultStatus::ErrorBadNCAHeader; return; @@ -84,10 +81,8 @@ NCA::NCA(VirtualFile file_, const NCA* base_nca) std::vector filesystems(fs_count); for (s32 i = 0; i < fs_count; i++) { NcaFsHeaderReader header_reader; - const Result rc = fs.OpenStorage(&filesystems[i], &header_reader, i); - if (R_FAILED(rc)) { - LOG_DEBUG(Loader, "File reader errored out during read of section {}: {:#x}", i, - rc.GetInnerValue()); + if (Result rc = fs.OpenStorage(&filesystems[i], &header_reader, i); R_FAILED(rc)) { + LOG_DEBUG(Loader, "File reader errored out during read of section {}: {:#x}", i, rc.GetInnerValue()); status = Loader::ResultStatus::ErrorBadNCAHeader; return; } -- 2.39.5