From e02fffa3cb036089aeb4e2f9a7aba49b4b27d7bd Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 30 Oct 2026 07:39:31 +0000 Subject: [PATCH] Reject a padding whose double overflows instead of letting it pass validation [patch] Padding * 2 wrapped negative for any padding above int.MaxValue / 2, so --padding 1500000000 passed Validate, every icon came out as 1-2 pixels of content, and the run exited 0. The comparison is now done in long, keeping the #122 boundaries. Fixes #153 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017vfJW2iVGcootGPPjA4P7Q --- IconHelper.Test/ArgumentsTests.cs | 17 +++++++++++++++++ IconHelper/Arguments.cs | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) 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."); }