Merge pull request #354 from wheremyfoodat/wheremyfoodat-patch-3

Fix reading from end of RomFS
This commit is contained in:
wheremyfoodat 2023-12-20 19:51:27 +02:00 committed by GitHub
commit bf050027c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions

View file

@ -142,7 +142,7 @@ std::optional<u32> NCCHArchive::readFile(FileSession* file, u64 offset, u32 size
case PathType::RomFS: { case PathType::RomFS: {
const u64 romFSSize = cxi->romFS.size; const u64 romFSSize = cxi->romFS.size;
const u64 romFSOffset = cxi->romFS.offset; 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"); Helpers::panic("Tried to read from NCCH with too big of an offset");
} }
@ -166,4 +166,4 @@ std::optional<u32> NCCHArchive::readFile(FileSession* file, u64 offset, u32 size
} }
return u32(bytesRead); return u32(bytesRead);
} }

View file

@ -83,7 +83,7 @@ std::optional<u32> SelfNCCHArchive::readFile(FileSession* file, u64 offset, u32
case PathType::RomFS: { case PathType::RomFS: {
const u64 romFSSize = cxi->romFS.size; const u64 romFSSize = cxi->romFS.size;
const u64 romFSOffset = cxi->romFS.offset; 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"); 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: { case PathType::ExeFS: {
const u64 exeFSSize = cxi->exeFS.size; const u64 exeFSSize = cxi->exeFS.size;
const u64 exeFSOffset = cxi->exeFS.offset; 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"); 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 romFSSize = cxi->romFS.size;
const u64 romFSOffset = cxi->romFS.offset; 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"); 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) { switch (type) {
case PathType::RomFS: { case PathType::RomFS: {
const u64 romFSSize = hb3dsx->romFSSize; 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"); Helpers::panic("Tried to read from SelfNCCH with too big of an offset");
} }
break; break;
@ -150,4 +150,4 @@ std::optional<u32> SelfNCCHArchive::readFile(FileSession* file, u64 offset, u32
} }
return u32(bytesRead); return u32(bytesRead);
} }