From 4c0dde1b815e2fd86f9d17213a138c69e526346d Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Mon, 20 Dec 2021 02:29:23 +0100 Subject: [PATCH] fix range check --- src/ImageSharp/Common/Helpers/Numerics.cs | 6 +++--- src/ImageSharp/ImageFrame{TPixel}.cs | 4 ++-- src/ImageSharp/Image{TPixel}.cs | 4 ++-- src/ImageSharp/Memory/Buffer2D{T}.cs | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ImageSharp/Common/Helpers/Numerics.cs b/src/ImageSharp/Common/Helpers/Numerics.cs index f88c54f0db..f271f6e5d2 100644 --- a/src/ImageSharp/Common/Helpers/Numerics.cs +++ b/src/ImageSharp/Common/Helpers/Numerics.cs @@ -978,9 +978,9 @@ namespace SixLabors.ImageSharp /// Tells whether input value is outside of the 0..max range. /// /// Value. - /// Maximum value, inclusive. + /// Maximum value, exclusive. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool IsOutOfRangeZeroToMax(int value, int max) - => (uint)value > (uint)max; + public static bool IsOutOfRangeZeroToExclusiveMax(int value, int max) + => (uint)value >= (uint)max; } } diff --git a/src/ImageSharp/ImageFrame{TPixel}.cs b/src/ImageSharp/ImageFrame{TPixel}.cs index fe026b3ebe..b43cf7a829 100644 --- a/src/ImageSharp/ImageFrame{TPixel}.cs +++ b/src/ImageSharp/ImageFrame{TPixel}.cs @@ -443,12 +443,12 @@ namespace SixLabors.ImageSharp [MethodImpl(InliningOptions.ShortMethod)] private void VerifyCoords(int x, int y) { - if (Numerics.IsOutOfRangeZeroToMax(x, this.Width)) + if (Numerics.IsOutOfRangeZeroToExclusiveMax(x, this.Width)) { ThrowArgumentOutOfRangeException(nameof(x)); } - if (Numerics.IsOutOfRangeZeroToMax(y, this.Height)) + if (Numerics.IsOutOfRangeZeroToExclusiveMax(y, this.Height)) { ThrowArgumentOutOfRangeException(nameof(y)); } diff --git a/src/ImageSharp/Image{TPixel}.cs b/src/ImageSharp/Image{TPixel}.cs index b25fa0d6af..e1016aa97a 100644 --- a/src/ImageSharp/Image{TPixel}.cs +++ b/src/ImageSharp/Image{TPixel}.cs @@ -452,12 +452,12 @@ namespace SixLabors.ImageSharp [MethodImpl(InliningOptions.ShortMethod)] private void VerifyCoords(int x, int y) { - if (Numerics.IsOutOfRangeZeroToMax(x, this.Width)) + if (Numerics.IsOutOfRangeZeroToExclusiveMax(x, this.Width)) { ThrowArgumentOutOfRangeException(nameof(x)); } - if (Numerics.IsOutOfRangeZeroToMax(y, this.Height)) + if (Numerics.IsOutOfRangeZeroToExclusiveMax(y, this.Height)) { ThrowArgumentOutOfRangeException(nameof(y)); } diff --git a/src/ImageSharp/Memory/Buffer2D{T}.cs b/src/ImageSharp/Memory/Buffer2D{T}.cs index bc97add5c9..0d9d444e06 100644 --- a/src/ImageSharp/Memory/Buffer2D{T}.cs +++ b/src/ImageSharp/Memory/Buffer2D{T}.cs @@ -97,7 +97,7 @@ namespace SixLabors.ImageSharp.Memory [MethodImpl(InliningOptions.ShortMethod)] public Span DangerousGetRowSpan(int y) { - if (Numerics.IsOutOfRangeZeroToMax(y, this.Height)) + if (Numerics.IsOutOfRangeZeroToExclusiveMax(y, this.Height)) { this.ThrowYOutOfRangeException(y); }