From 2993c11865e3ed99db9aeb338208bb1e2d5fc8b5 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sun, 28 Jun 2020 02:52:02 -0700 Subject: [PATCH] fs: more IndirectStorage::OperatePerEntry updates/fixes --- ...ssystem_indirect_storage_template_impl.hpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/libstratosphere/include/stratosphere/fssystem/fssystem_indirect_storage_template_impl.hpp b/libstratosphere/include/stratosphere/fssystem/fssystem_indirect_storage_template_impl.hpp index 506fdf64..44dab4f6 100644 --- a/libstratosphere/include/stratosphere/fssystem/fssystem_indirect_storage_template_impl.hpp +++ b/libstratosphere/include/stratosphere/fssystem/fssystem_indirect_storage_template_impl.hpp @@ -64,10 +64,25 @@ namespace ams::fssystem { /* Process a base storage entry. */ if (cr_info.CanDo()) { + /* Ensure that we can process. */ R_UNLESS(cur_entry.storage_index == 0, fs::ResultInvalidIndirectEntryStorageIndex()); - const auto data_offset = cur_offset - cur_entry_offset; - R_TRY(func(std::addressof(this->data_storage[0]), cur_entry.GetPhysicalOffset() + data_offset, cur_offset, static_cast(cr_info.GetReadSize()))); + /* Get the current data storage's size. */ + s64 cur_data_storage_size; + R_TRY(this->data_storage[0].GetSize(std::addressof(cur_data_storage_size))); + + /* Ensure that we remain within range. */ + const auto data_offset = cur_offset - cur_entry_offset; + const auto cur_entry_phys_offset = cur_entry.GetPhysicalOffset(); + const auto cur_size = static_cast(cr_info.GetReadSize()); + R_UNLESS(0 <= cur_entry_phys_offset && cur_entry_phys_offset <= cur_data_storage_size, fs::ResultInvalidIndirectEntryOffset()); + R_UNLESS(cur_entry_phys_offset + data_offset + cur_size <= cur_data_storage_size, fs::ResultInvalidIndirectStorageSize()); + + /* Operate. */ + R_TRY(func(std::addressof(this->data_storage[0]), cur_entry_phys_offset + data_offset, cur_offset, cur_size)); + + /* Mark as done. */ + cr_info.Done(); } }