From d31e79ebc8cd2d12946f1d09707cbb84d0ab51c5 Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Wed, 20 Dec 2023 19:32:07 +0200 Subject: [PATCH 1/2] [SelfNCCH] Fix reading from end of RomFS --- src/core/fs/archive_self_ncch.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/fs/archive_self_ncch.cpp b/src/core/fs/archive_self_ncch.cpp index 9c911769..9369152d 100644 --- a/src/core/fs/archive_self_ncch.cpp +++ b/src/core/fs/archive_self_ncch.cpp @@ -83,7 +83,7 @@ std::optional SelfNCCHArchive::readFile(FileSession* file, u64 offset, u32 case PathType::RomFS: { const u64 romFSSize = cxi->romFS.size; const u64 romFSOffset = cxi->romFS.offset; - if ((offset >> 32) || (offset >= romFSSize) || (offset + size >= romFSSize)) { + if ((offset >> 32) || (offset >= romFSSize) || (offset + size > romFSSize)) { Helpers::panic("Tried to read from SelfNCCH with too big of an offset"); } @@ -95,7 +95,7 @@ std::optional SelfNCCHArchive::readFile(FileSession* file, u64 offset, u32 case PathType::ExeFS: { const u64 exeFSSize = cxi->exeFS.size; const u64 exeFSOffset = cxi->exeFS.offset; - if ((offset >> 32) || (offset >= exeFSSize) || (offset + size >= exeFSSize)) { + if ((offset >> 32) || (offset >= exeFSSize) || (offset + size > exeFSSize)) { Helpers::panic("Tried to read from SelfNCCH with too big of an offset"); } @@ -110,7 +110,7 @@ std::optional SelfNCCHArchive::readFile(FileSession* file, u64 offset, u32 const u64 romFSSize = cxi->romFS.size; const u64 romFSOffset = cxi->romFS.offset; - if ((offset >> 32) || (offset >= romFSSize) || (offset + size >= romFSSize)) { + if ((offset >> 32) || (offset >= romFSSize) || (offset + size > romFSSize)) { Helpers::panic("Tried to read from SelfNCCH with too big of an offset"); } @@ -129,7 +129,7 @@ std::optional SelfNCCHArchive::readFile(FileSession* file, u64 offset, u32 switch (type) { case PathType::RomFS: { const u64 romFSSize = hb3dsx->romFSSize; - if ((offset >> 32) || (offset >= romFSSize) || (offset + size >= romFSSize)) { + if ((offset >> 32) || (offset >= romFSSize) || (offset + size > romFSSize)) { Helpers::panic("Tried to read from SelfNCCH with too big of an offset"); } break; @@ -150,4 +150,4 @@ std::optional SelfNCCHArchive::readFile(FileSession* file, u64 offset, u32 } return u32(bytesRead); -} \ No newline at end of file +} From 0f2fa4e738d9fab618b6f83cf10cb6bc09d27900 Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Wed, 20 Dec 2023 19:33:38 +0200 Subject: [PATCH 2/2] Same for NCCH archive --- src/core/fs/archive_ncch.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/fs/archive_ncch.cpp b/src/core/fs/archive_ncch.cpp index 5935a0c5..d5a4bab5 100644 --- a/src/core/fs/archive_ncch.cpp +++ b/src/core/fs/archive_ncch.cpp @@ -142,7 +142,7 @@ std::optional NCCHArchive::readFile(FileSession* file, u64 offset, u32 size case PathType::RomFS: { const u64 romFSSize = cxi->romFS.size; const u64 romFSOffset = cxi->romFS.offset; - if ((offset >> 32) || (offset >= romFSSize) || (offset + size >= romFSSize)) { + if ((offset >> 32) || (offset >= romFSSize) || (offset + size > romFSSize)) { Helpers::panic("Tried to read from NCCH with too big of an offset"); } @@ -166,4 +166,4 @@ std::optional NCCHArchive::readFile(FileSession* file, u64 offset, u32 size } return u32(bytesRead); -} \ No newline at end of file +}