From fb574064c9e7b74f912ce56c308e99c133b0108c Mon Sep 17 00:00:00 2001 From: VaDiM Date: Tue, 7 Mar 2023 06:55:45 +0300 Subject: [PATCH] [GUI] Avoid overflow in alphanum sorting --- AssetStudioGUI/Components/AlphanumComparatorFast.cs | 12 +++++++++--- .../Components/AlphanumComparatorFastNet.cs | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/AssetStudioGUI/Components/AlphanumComparatorFast.cs b/AssetStudioGUI/Components/AlphanumComparatorFast.cs index de31d5b..4e46b8b 100644 --- a/AssetStudioGUI/Components/AlphanumComparatorFast.cs +++ b/AssetStudioGUI/Components/AlphanumComparatorFast.cs @@ -67,9 +67,15 @@ namespace AssetStudioGUI if (char.IsDigit(space1[0]) && char.IsDigit(space2[0])) { - int thisNumericChunk = int.Parse(new string(space1)); - int thatNumericChunk = int.Parse(new string(space2)); - result = thisNumericChunk.CompareTo(thatNumericChunk); + if (long.TryParse(new string(space1), out long thisNumericChunk) && + long.TryParse(new string(space2), out long thatNumericChunk)) + { + result = thisNumericChunk.CompareTo(thatNumericChunk); + } + else + { + result = MemoryExtensions.CompareTo(space1, space2, StringComparison.Ordinal); + } } else { diff --git a/AssetStudioGUI/Components/AlphanumComparatorFastNet.cs b/AssetStudioGUI/Components/AlphanumComparatorFastNet.cs index bf9364c..7edd5f9 100644 --- a/AssetStudioGUI/Components/AlphanumComparatorFastNet.cs +++ b/AssetStudioGUI/Components/AlphanumComparatorFastNet.cs @@ -72,9 +72,15 @@ namespace AssetStudioGUI if (char.IsDigit(space1[0]) && char.IsDigit(space2[0])) { - int thisNumericChunk = int.Parse(space1); - int thatNumericChunk = int.Parse(space2); - result = thisNumericChunk.CompareTo(thatNumericChunk); + if (long.TryParse(space1, out long thisNumericChunk) && + long.TryParse(space2, out long thatNumericChunk)) + { + result = thisNumericChunk.CompareTo(thatNumericChunk); + } + else + { + result = MemoryExtensions.CompareTo(space1, space2, StringComparison.Ordinal); + } } else {