From 63709d7d298968d62c754c5f6a114316de3bec61 Mon Sep 17 00:00:00 2001 From: Alexey 'Cluster' Avdyukhin Date: Thu, 27 Oct 2022 17:40:26 +0400 Subject: Crop overflow check. --- NesTiler/FastBitmap.cs | 2 ++ NesTiler/Program.cs | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/NesTiler/FastBitmap.cs b/NesTiler/FastBitmap.cs index fb92468..5910f43 100644 --- a/NesTiler/FastBitmap.cs +++ b/NesTiler/FastBitmap.cs @@ -1,4 +1,5 @@ using SkiaSharp; +using System; using System.Collections.Generic; using System.Drawing; using System.Linq; @@ -17,6 +18,7 @@ namespace com.clusterrr.Famicom.NesTiler { Width = skBitmap.Width; Height = height <= 0 ? skBitmap.Height - verticalOffset : height; + if (skBitmap.Height - verticalOffset - Height <= 0) throw new InvalidOperationException("Invalid image height."); var pixels = skBitmap.Pixels; colors = skBitmap.Pixels.Skip(verticalOffset * Width).Take(Width * Height).Select(p => Color.FromArgb(p.Alpha, p.Red, p.Green, p.Blue)).ToArray(); } diff --git a/NesTiler/Program.cs b/NesTiler/Program.cs index 09e6519..852cbc1 100644 --- a/NesTiler/Program.cs +++ b/NesTiler/Program.cs @@ -225,7 +225,7 @@ namespace com.clusterrr.Famicom.NesTiler if (calculatedPalettes.Count > maxCalculatedPaletteCount && !c.Lossy) { - throw new ArgumentOutOfRangeException($"Can't fit {calculatedPalettes.Count} palettes, {maxCalculatedPaletteCount} is maximum."); + throw new InvalidOperationException($"Can't fit {calculatedPalettes.Count} palettes, {maxCalculatedPaletteCount} is maximum."); } // Select palettes -- cgit v1.2.3