Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions IconHelper.Test/ArgumentsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,23 @@ public void ValidateAcceptsTheSmallestSizesThePipelineHandles(int size, int padd
Assert.IsTrue(valid, $"Expected --size {size} --padding {padding} to be valid but got: {string.Join(", ", errors)}");
}

[TestMethod]
[DataRow((int.MaxValue / 2) + 1)]
[DataRow(int.MaxValue)]
public void ValidateRejectsPaddingWhoseDoubleOverflowsAnInt(int padding)
{
using TempDirectory temp = new();
Arguments args = ValidArguments(temp);
args.Size = 128;
args.Padding = padding;

bool valid = args.Validate(out Collection<string> errors);

Assert.IsFalse(valid, $"Padding {padding} is far above half of 128 and should be rejected.");
Assert.HasCount(1, errors);
Assert.AreEqual("Padding must be less than half the size of the image.", errors[0]);
}

[TestMethod]
public void ValidateRejectsPaddingThatLeavesNoContentOnASmallSize()
{
Expand Down
3 changes: 2 additions & 1 deletion IconHelper/Arguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ internal bool Validate(out Collection<string> errors)
// Doubled rather than halved: Size / 2 rounds an odd size down, which rejected padding the
// pipeline handles (--size 3 --padding 1) and even the default 0 at --size 1. This is the
// bound EffectivePadding clamps to, (size - 1) / 2, so at least one pixel of content is left.
else if (Size > 0 && Padding * 2 >= Size)
// Widened to long so a padding above int.MaxValue / 2 cannot wrap negative and pass.
else if (Size > 0 && (long)Padding * 2 >= Size)
{
errors.Add("Padding must be less than half the size of the image.");
}
Expand Down
Loading