From e5f808cd2d5dce413d279927d7e1e7ddade816ad Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Sun, 27 Jan 2019 19:39:06 -0600 Subject: [PATCH] Don't read invalid NAX0 files --- src/LibHac/IO/AesXtsDirectory.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/LibHac/IO/AesXtsDirectory.cs b/src/LibHac/IO/AesXtsDirectory.cs index 7c46dee1..a8ec03cd 100644 --- a/src/LibHac/IO/AesXtsDirectory.cs +++ b/src/LibHac/IO/AesXtsDirectory.cs @@ -32,6 +32,8 @@ namespace LibHac.IO else { long size = GetAesXtsFileSize(entry.FullPath); + if (size == -1) continue; + yield return new DirectoryEntry(entry.Name, entry.FullPath, entry.Type, size); } } @@ -42,12 +44,22 @@ namespace LibHac.IO return BaseDirectory.GetEntryCount(); } + /// + /// Reads the size of a NAX0 file from its header. Returns -1 on error. + /// + /// + /// private long GetAesXtsFileSize(string path) { try { using (IFile file = BaseFileSystem.OpenFile(path, OpenMode.Read)) { + if (file.GetSize() < 0x50) + { + return -1; + } + var buffer = new byte[8]; file.Read(buffer, 0x20); @@ -59,7 +71,7 @@ namespace LibHac.IO } catch (ArgumentOutOfRangeException) { - return 0; + return -1; } } }