Explorar o código

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.
Lioncash %!s(int64=8) %!d(string=hai) anos
pai
achega
9b22f856c2
Modificáronse 1 ficheiros con 6 adicións e 4 borrados
  1. 6 4
      src/core/loader/nso.cpp

+ 6 - 4
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,