Skip to content

Commit 762d72b

Browse files
NguyenThuyLanLanThuyNguyen
authored andcommitted
update ImageSharpMiddlewareOption for fixing invalid width and height (#17126)
Co-authored-by: Lan Nguyen Thuy <[email protected]> (cherry picked from commit 9b19d63)
1 parent c9c9374 commit 762d72b

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/Umbraco.Cms.Imaging.ImageSharp/ConfigureImageSharpMiddlewareOptions.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Globalization;
12
using Microsoft.AspNetCore.Http;
23
using Microsoft.AspNetCore.Http.Headers;
34
using Microsoft.Extensions.Options;
@@ -48,16 +49,26 @@ public void Configure(ImageSharpMiddlewareOptions options)
4849
return Task.CompletedTask;
4950
}
5051

51-
int width = context.Parser.ParseValue<int>(context.Commands.GetValueOrDefault(ResizeWebProcessor.Width), context.Culture);
52-
if (width <= 0 || width > _imagingSettings.Resize.MaxWidth)
52+
if (context.Commands.Contains(ResizeWebProcessor.Width))
5353
{
54-
context.Commands.Remove(ResizeWebProcessor.Width);
54+
if (!int.TryParse(context.Commands.GetValueOrDefault(ResizeWebProcessor.Width), NumberStyles.Integer,
55+
CultureInfo.InvariantCulture, out var width)
56+
|| width < 0
57+
|| width >= _imagingSettings.Resize.MaxWidth)
58+
{
59+
context.Commands.Remove(ResizeWebProcessor.Width);
60+
}
5561
}
5662

57-
int height = context.Parser.ParseValue<int>(context.Commands.GetValueOrDefault(ResizeWebProcessor.Height), context.Culture);
58-
if (height <= 0 || height > _imagingSettings.Resize.MaxHeight)
63+
if (context.Commands.Contains(ResizeWebProcessor.Height))
5964
{
60-
context.Commands.Remove(ResizeWebProcessor.Height);
65+
if (!int.TryParse(context.Commands.GetValueOrDefault(ResizeWebProcessor.Height), NumberStyles.Integer,
66+
CultureInfo.InvariantCulture, out var height)
67+
|| height < 0
68+
|| height >= _imagingSettings.Resize.MaxHeight)
69+
{
70+
context.Commands.Remove(ResizeWebProcessor.Height);
71+
}
6172
}
6273

6374
return Task.CompletedTask;

0 commit comments

Comments
 (0)