diff --git a/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_bucket_tree.hpp b/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_bucket_tree.hpp index fdf718b4d..370de5969 100644 --- a/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_bucket_tree.hpp +++ b/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_bucket_tree.hpp @@ -126,7 +126,7 @@ namespace ams::fssystem { this->allocator = nullptr; } - void FillSzero(size_t node_size) const { + void FillZero(size_t node_size) const { if (this->header) { std::memset(this->header, 0, node_size); } @@ -298,7 +298,7 @@ namespace ams::fssystem { } bool IsValid() const { return this->entry_index >= 0; } - bool CanMoveNext() const { return this->IsValid() && (this->entry_index + 1 < this->entry_set.info.count || this->entry_set.info.index + 1 < this->entry_set.info.count); } + bool CanMoveNext() const { return this->IsValid() && (this->entry_index + 1 < this->entry_set.info.count || this->entry_set.info.index + 1 < this->entry_set_count); } bool CanMovePrevious() const { return this->IsValid() && (this->entry_index > 0 || this->entry_set.info.index > 0); } Result MoveNext(); diff --git a/libraries/libstratosphere/source/fssystem/fssystem_bucket_tree.cpp b/libraries/libstratosphere/source/fssystem/fssystem_bucket_tree.cpp index 2927777d3..9888bf237 100644 --- a/libraries/libstratosphere/source/fssystem/fssystem_bucket_tree.cpp +++ b/libraries/libstratosphere/source/fssystem/fssystem_bucket_tree.cpp @@ -130,12 +130,12 @@ namespace ams::fssystem { } Result BucketTree::NodeHeader::Verify(s32 node_index, size_t node_size, size_t entry_size) const { - R_UNLESS(this->index == node_index, fs::ResultInvalidArgument()); - R_UNLESS(entry_size == 0 || node_size < entry_size + NodeHeaderSize, fs::ResultInvalidSize()); + R_UNLESS(this->index == node_index, fs::ResultInvalidBucketTreeNodeIndex()); + R_UNLESS(entry_size != 0 && node_size >= entry_size + NodeHeaderSize, fs::ResultInvalidSize()); const size_t max_entry_count = (node_size - NodeHeaderSize) / entry_size; R_UNLESS(this->count > 0 && static_cast(this->count) <= max_entry_count, fs::ResultInvalidBucketTreeNodeEntryCount()); - R_UNLESS(this->offset > 0, fs::ResultInvalidBucketTreeNodeOffset()); + R_UNLESS(this->offset >= 0, fs::ResultInvalidBucketTreeNodeOffset()); return ResultSuccess(); } @@ -440,7 +440,7 @@ namespace ams::fssystem { /* Create the node, and find. */ StorageNode node(sizeof(s64), header.count); node.Find(buffer, virtual_address); - R_UNLESS(node.GetIndex() >= 0, fs::ResultOutOfRange()); + R_UNLESS(node.GetIndex() >= 0, fs::ResultInvalidBucketTreeVirtualOffset()); /* Return the index. */ *out_index = this->tree->GetEntrySetIndex(header.index, node.GetIndex()); @@ -485,7 +485,7 @@ namespace ams::fssystem { const auto entry_size = this->tree->entry_size; const auto entry_set_size = this->tree->node_size; const auto entry_set_offset = entry_set_index * static_cast(entry_set_size); - fs::SubStorage &storage = tree->node_storage; + fs::SubStorage &storage = tree->entry_storage; /* Read the entry set. */ R_TRY(storage.Read(entry_set_offset, buffer, entry_set_size)); @@ -517,7 +517,7 @@ namespace ams::fssystem { const auto entry_size = this->tree->entry_size; const auto entry_set_size = this->tree->node_size; const auto entry_set_offset = entry_set_index * static_cast(entry_set_size); - fs::SubStorage &storage = tree->node_storage; + fs::SubStorage &storage = tree->entry_storage; /* Read and validate the entry_set. */ EntrySetHeader entry_set; diff --git a/libraries/libvapours/include/vapours/results/fs_results.hpp b/libraries/libvapours/include/vapours/results/fs_results.hpp index c4e9962ec..0eeb9ada7 100644 --- a/libraries/libvapours/include/vapours/results/fs_results.hpp +++ b/libraries/libvapours/include/vapours/results/fs_results.hpp @@ -141,6 +141,8 @@ namespace ams::fs { R_DEFINE_ERROR_RESULT(InvalidBucketTreeNodeOffset, 4035); R_DEFINE_ERROR_RESULT(InvalidBucketTreeEntryOffset, 4036); R_DEFINE_ERROR_RESULT(InvalidBucketTreeEntrySetOffset, 4037); + R_DEFINE_ERROR_RESULT(InvalidBucketTreeNodeIndex, 4038); + R_DEFINE_ERROR_RESULT(InvalidBucketTreeVirtualOffset, 4039); R_DEFINE_ERROR_RANGE(RomNcaCorrupted, 4041, 4139); R_DEFINE_ERROR_RANGE(RomNcaFileSystemCorrupted, 4051, 4069);