From f197b88dd75c9d18b9fff418f426e028727b290a Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Thu, 25 Jun 2020 17:36:05 -0700 Subject: [PATCH] fs: update IndirectStorage for 10.x, bugfixes --- .../fssystem/fssystem_indirect_storage.hpp | 2 +- .../fssystem_indirect_storage_template_impl.hpp | 11 ++++++++++- .../fssystem/fssystem_nca_file_system_driver.cpp | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_indirect_storage.hpp b/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_indirect_storage.hpp index 0fdde75a2..0631e8e67 100644 --- a/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_indirect_storage.hpp +++ b/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_indirect_storage.hpp @@ -133,7 +133,7 @@ namespace ams::fssystem { virtual Result GetSize(s64 *out) override { AMS_ASSERT(out != nullptr); - *out = this->table.GetSize(); + *out = this->table.GetEnd(); return ResultSuccess(); } diff --git a/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_indirect_storage_template_impl.hpp b/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_indirect_storage_template_impl.hpp index 01ddcc8b5..506fdf642 100644 --- a/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_indirect_storage_template_impl.hpp +++ b/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_indirect_storage_template_impl.hpp @@ -101,7 +101,16 @@ namespace ams::fssystem { } if (needs_operate) { - R_TRY(func(std::addressof(this->data_storage[cur_entry.storage_index]), cur_entry.GetPhysicalOffset() + data_offset, cur_offset, cur_size)); + /* Get the current data storage's size. */ + s64 cur_data_storage_size; + R_TRY(this->data_storage[cur_entry.storage_index].GetSize(std::addressof(cur_data_storage_size))); + + /* Ensure that we remain within range. */ + const auto cur_entry_phys_offset = cur_entry.GetPhysicalOffset(); + R_UNLESS(0 <= cur_entry_phys_offset && cur_entry_phys_offset <= cur_data_storage_size, fs::ResultIndirectStorageCorrupted()); + R_UNLESS(cur_entry_phys_offset + data_offset + cur_size <= cur_data_storage_size, fs::ResultIndirectStorageCorrupted()); + + R_TRY(func(std::addressof(this->data_storage[cur_entry.storage_index]), cur_entry_phys_offset + data_offset, cur_offset, cur_size)); } cur_offset += cur_size; diff --git a/libraries/libstratosphere/source/fssystem/fssystem_nca_file_system_driver.cpp b/libraries/libstratosphere/source/fssystem/fssystem_nca_file_system_driver.cpp index 171ac9317..c1afd1860 100644 --- a/libraries/libstratosphere/source/fssystem/fssystem_nca_file_system_driver.cpp +++ b/libraries/libstratosphere/source/fssystem/fssystem_nca_file_system_driver.cpp @@ -888,7 +888,7 @@ namespace ams::fssystem { /* Set the storage holder's storages. */ storage->SetStorage(0, original_storage.get(), 0, original_data_size); - storage->SetStorage(1, indirect_table_storage.get(), 0, indirect_data_size); + storage->SetStorage(1, indirect_data_storage.get(), 0, indirect_data_size); storage->Set(std::move(base_storage), std::move(original_storage), std::move(indirect_table_storage), std::move(indirect_data_storage)); /* Set the indirect storage. */