[SelfNCCH] Fix reading from end of RomFS

This commit is contained in:
wheremyfoodat
2023-12-20 19:32:07 +02:00
committed by GitHub
parent 6c73fb13c5
commit d31e79ebc8

View File

@@ -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");
}
@@ -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");
}
@@ -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");
}
@@ -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;
@@ -150,4 +150,4 @@ std::optional<u32> SelfNCCHArchive::readFile(FileSession* file, u64 offset, u32
}
return u32(bytesRead);
}
}