From 39f952015f86e26a9836e7434da57c6f0b2f4006 Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Sun, 20 Jan 2019 15:39:19 -0600 Subject: [PATCH] Catch errors when checking an AesXtsFile's size --- src/LibHac/IO/AesXtsDirectory.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/LibHac/IO/AesXtsDirectory.cs b/src/LibHac/IO/AesXtsDirectory.cs index afb1acba..7c46dee1 100644 --- a/src/LibHac/IO/AesXtsDirectory.cs +++ b/src/LibHac/IO/AesXtsDirectory.cs @@ -44,15 +44,22 @@ namespace LibHac.IO private long GetAesXtsFileSize(string path) { - using (IFile file = BaseFileSystem.OpenFile(path, OpenMode.Read)) + try { - var buffer = new byte[8]; + using (IFile file = BaseFileSystem.OpenFile(path, OpenMode.Read)) + { + var buffer = new byte[8]; - file.Read(buffer, 0x20); - if (BitConverter.ToUInt32(buffer, 0) != 0x3058414E) return 0; + file.Read(buffer, 0x20); + if (BitConverter.ToUInt32(buffer, 0) != 0x3058414E) return 0; - file.Read(buffer, 0x48); - return BitConverter.ToInt32(buffer, 0); + file.Read(buffer, 0x48); + return BitConverter.ToInt32(buffer, 0); + } + } + catch (ArgumentOutOfRangeException) + { + return 0; } } }