diff --git a/IconHelper.Test/ArgumentsTests.cs b/IconHelper.Test/ArgumentsTests.cs index af801bb..c806692 100644 --- a/IconHelper.Test/ArgumentsTests.cs +++ b/IconHelper.Test/ArgumentsTests.cs @@ -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 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() { diff --git a/IconHelper/Arguments.cs b/IconHelper/Arguments.cs index 946a67c..990f0e8 100644 --- a/IconHelper/Arguments.cs +++ b/IconHelper/Arguments.cs @@ -53,7 +53,8 @@ internal bool Validate(out Collection 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."); }