Skip to content

Commit 708c592

Browse files
authored
fix: add guards for MagickImage.HoughLine (#1566)
1 parent 9c11be7 commit 708c592

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/Magick.NET/MagickImage.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3328,7 +3328,13 @@ public void HoughLine()
33283328
/// <param name="threshold">The line count threshold.</param>
33293329
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
33303330
public void HoughLine(int width, int height, int threshold)
3331-
=> _nativeInstance.HoughLine(width, height, threshold);
3331+
{
3332+
Throw.IfNegative(nameof(width), width);
3333+
Throw.IfNegative(nameof(height), height);
3334+
Throw.IfNegative(nameof(threshold), threshold);
3335+
3336+
_nativeInstance.HoughLine(width, height, threshold);
3337+
}
33323338

33333339
/// <summary>
33343340
/// Implode image (special effect).

tests/Magick.NET.Tests/MagickImageTests/TheHoughLineMethod.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
22
// Licensed under the Apache License, Version 2.0.
33

4+
using System;
45
using ImageMagick;
56
using Xunit;
67

@@ -10,6 +11,27 @@ public partial class MagickImageTests
1011
{
1112
public class TheHoughLineMethod
1213
{
14+
[Fact]
15+
public void ShouldThrowExceptionWhenWidthIsNegative()
16+
{
17+
using var image = new MagickImage(Files.ConnectedComponentsPNG);
18+
Assert.Throws<ArgumentException>("width", () => image.HoughLine(-1, 0, 0));
19+
}
20+
21+
[Fact]
22+
public void ShouldThrowExceptionWhenHeightIsNegative()
23+
{
24+
using var image = new MagickImage(Files.ConnectedComponentsPNG);
25+
Assert.Throws<ArgumentException>("height", () => image.HoughLine(0, -1, 0));
26+
}
27+
28+
[Fact]
29+
public void ShouldThrowExceptionWhenThresholdIsNegative()
30+
{
31+
using var image = new MagickImage(Files.ConnectedComponentsPNG);
32+
Assert.Throws<ArgumentException>("threshold", () => image.HoughLine(0, 0, -1));
33+
}
34+
1335
[Fact]
1436
public void ShouldIdentifyLinesInImage()
1537
{

0 commit comments

Comments
 (0)