diff options
author | Lioncash <mathew1800@gmail.com> | 2018-07-19 12:40:06 -0400 |
---|---|---|
committer | Lioncash <mathew1800@gmail.com> | 2018-07-19 12:43:21 -0400 |
commit | 9b22f856c2f644af721568a6f6b23bd66e7beb93 (patch) | |
tree | 841c4a2ad026152dcf1571f3bab77860567da796 /src/core/loader/nso.cpp | |
parent | 758c357868fca86edf3642a5a7e658839d35183c (diff) |
loader/nso: Check if read succeeded in IdentifyFile() before checking magic value
We should always assume the filesystem is volatile and check each IO
operation. While we're at it reorganize checks so that early-out errors
are near one another.
Diffstat (limited to 'src/core/loader/nso.cpp')
-rw-r--r-- | src/core/loader/nso.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index 2beb85fbf..59049d016 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp @@ -55,13 +55,15 @@ AppLoader_NSO::AppLoader_NSO(FileSys::VirtualFile file) : AppLoader(std::move(fi FileType AppLoader_NSO::IdentifyType(const FileSys::VirtualFile& file) { u32 magic = 0; - file->ReadObject(&magic); + if (file->ReadObject(&magic) != sizeof(magic)) { + return FileType::Error; + } - if (Common::MakeMagic('N', 'S', 'O', '0') == magic) { - return FileType::NSO; + if (Common::MakeMagic('N', 'S', 'O', '0') != magic) { + return FileType::Error; } - return FileType::Error; + return FileType::NSO; } static std::vector<u8> DecompressSegment(const std::vector<u8>& compressed_data, |