Browse Source

fix range check

pull/1901/head
Anton Firszov 4 years ago
parent
commit
4c0dde1b81
  1. 6
      src/ImageSharp/Common/Helpers/Numerics.cs
  2. 4
      src/ImageSharp/ImageFrame{TPixel}.cs
  3. 4
      src/ImageSharp/Image{TPixel}.cs
  4. 2
      src/ImageSharp/Memory/Buffer2D{T}.cs

6
src/ImageSharp/Common/Helpers/Numerics.cs

@ -978,9 +978,9 @@ namespace SixLabors.ImageSharp
/// Tells whether input value is outside of the 0..max range. /// Tells whether input value is outside of the 0..max range.
/// </summary> /// </summary>
/// <param name="value">Value.</param> /// <param name="value">Value.</param>
/// <param name="max">Maximum value, inclusive.</param> /// <param name="max">Maximum value, exclusive.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsOutOfRangeZeroToMax(int value, int max) public static bool IsOutOfRangeZeroToExclusiveMax(int value, int max)
=> (uint)value > (uint)max; => (uint)value >= (uint)max;
} }
} }

4
src/ImageSharp/ImageFrame{TPixel}.cs

@ -443,12 +443,12 @@ namespace SixLabors.ImageSharp
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
private void VerifyCoords(int x, int y) private void VerifyCoords(int x, int y)
{ {
if (Numerics.IsOutOfRangeZeroToMax(x, this.Width)) if (Numerics.IsOutOfRangeZeroToExclusiveMax(x, this.Width))
{ {
ThrowArgumentOutOfRangeException(nameof(x)); ThrowArgumentOutOfRangeException(nameof(x));
} }
if (Numerics.IsOutOfRangeZeroToMax(y, this.Height)) if (Numerics.IsOutOfRangeZeroToExclusiveMax(y, this.Height))
{ {
ThrowArgumentOutOfRangeException(nameof(y)); ThrowArgumentOutOfRangeException(nameof(y));
} }

4
src/ImageSharp/Image{TPixel}.cs

@ -452,12 +452,12 @@ namespace SixLabors.ImageSharp
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
private void VerifyCoords(int x, int y) private void VerifyCoords(int x, int y)
{ {
if (Numerics.IsOutOfRangeZeroToMax(x, this.Width)) if (Numerics.IsOutOfRangeZeroToExclusiveMax(x, this.Width))
{ {
ThrowArgumentOutOfRangeException(nameof(x)); ThrowArgumentOutOfRangeException(nameof(x));
} }
if (Numerics.IsOutOfRangeZeroToMax(y, this.Height)) if (Numerics.IsOutOfRangeZeroToExclusiveMax(y, this.Height))
{ {
ThrowArgumentOutOfRangeException(nameof(y)); ThrowArgumentOutOfRangeException(nameof(y));
} }

2
src/ImageSharp/Memory/Buffer2D{T}.cs

@ -97,7 +97,7 @@ namespace SixLabors.ImageSharp.Memory
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public Span<T> DangerousGetRowSpan(int y) public Span<T> DangerousGetRowSpan(int y)
{ {
if (Numerics.IsOutOfRangeZeroToMax(y, this.Height)) if (Numerics.IsOutOfRangeZeroToExclusiveMax(y, this.Height))
{ {
this.ThrowYOutOfRangeException(y); this.ThrowYOutOfRangeException(y);
} }

Loading…
Cancel
Save