From 77a41f31972e5aeb9a4db17e516432fa94fb08de Mon Sep 17 00:00:00 2001 From: Souryo Date: Sun, 6 Aug 2017 16:45:01 -0400 Subject: [PATCH] UI: Guard against potentially corrupted data in the recent games zip files --- GUI.NET/Controls/ctrlRecentGames.cs | 30 +++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/GUI.NET/Controls/ctrlRecentGames.cs b/GUI.NET/Controls/ctrlRecentGames.cs index 39995f9c..cd73c52c 100644 --- a/GUI.NET/Controls/ctrlRecentGames.cs +++ b/GUI.NET/Controls/ctrlRecentGames.cs @@ -135,13 +135,17 @@ namespace Mesen.GUI.Controls lblGameName.Text = Path.GetFileNameWithoutExtension(_recentGames[_currentIndex].RomName); lblSaveDate.Text = _recentGames[_currentIndex].Timestamp.ToString(); - ZipArchive zip = new ZipArchive(new MemoryStream(File.ReadAllBytes(_recentGames[_currentIndex].FileName))); - ZipArchiveEntry entry = zip.GetEntry("Screenshot.png"); - if(entry != null) { - using(Stream stream = entry.Open()) { - picPreviousState.Image = Image.FromStream(stream); + try { + ZipArchive zip = new ZipArchive(new MemoryStream(File.ReadAllBytes(_recentGames[_currentIndex].FileName))); + ZipArchiveEntry entry = zip.GetEntry("Screenshot.png"); + if(entry != null) { + using(Stream stream = entry.Open()) { + picPreviousState.Image = Image.FromStream(stream); + } + } else { + picPreviousState.Image = null; } - } else { + } catch { picPreviousState.Image = null; } UpdateSize(); @@ -153,13 +157,15 @@ namespace Mesen.GUI.Controls tlpPreviousState.Visible = false; Size maxSize = new Size(this.Size.Width - 120, this.Size.Height - 50); - double xRatio = (double)picPreviousState.Image.Width / maxSize.Width; - double yRatio = (double)picPreviousState.Image.Height / maxSize.Height; - double ratio = Math.Max(xRatio, yRatio); + if(picPreviousState.Image != null) { + double xRatio = (double)picPreviousState.Image.Width / maxSize.Width; + double yRatio = (double)picPreviousState.Image.Height / maxSize.Height; + double ratio = Math.Max(xRatio, yRatio); - Size newSize = new Size((int)(picPreviousState.Image.Width / ratio), (int)(picPreviousState.Image.Height / ratio)); - picPreviousState.Size = newSize; - pnlPreviousState.Size = new Size(newSize.Width+4, newSize.Height+4); + Size newSize = new Size((int)(picPreviousState.Image.Width / ratio), (int)(picPreviousState.Image.Height / ratio)); + picPreviousState.Size = newSize; + pnlPreviousState.Size = new Size(newSize.Width+4, newSize.Height+4); + } tlpPreviousState.Visible = true; }