Skip to content

Commit

Permalink
Merge pull request #354 from wheremyfoodat/wheremyfoodat-patch-3
Browse files Browse the repository at this point in the history
Fix reading from end of RomFS
  • Loading branch information
wheremyfoodat authored Dec 20, 2023
2 parents 6c73fb1 + 0f2fa4e commit bf05002
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/core/fs/archive_ncch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ std::optional<u32> 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");
}

Expand All @@ -166,4 +166,4 @@ std::optional<u32> NCCHArchive::readFile(FileSession* file, u64 offset, u32 size
}

return u32(bytesRead);
}
}
10 changes: 5 additions & 5 deletions src/core/fs/archive_self_ncch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ std::optional<u32> 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");
}

Expand All @@ -95,7 +95,7 @@ std::optional<u32> 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");
}

Expand All @@ -110,7 +110,7 @@ std::optional<u32> 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");
}

Expand All @@ -129,7 +129,7 @@ std::optional<u32> 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;
Expand All @@ -150,4 +150,4 @@ std::optional<u32> SelfNCCHArchive::readFile(FileSession* file, u64 offset, u32
}

return u32(bytesRead);
}
}

0 comments on commit bf05002

Please sign in to comment.