Skip to content

Commit baa8c7b

Browse files
Fix pad memory access error
1 parent e6ab983 commit baa8c7b

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

src/ImageSharp/Processing/Extensions/Transforms/PadExtensions.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Apache License, Version 2.0.
33

4+
using System;
5+
46
namespace SixLabors.ImageSharp.Processing
57
{
68
/// <summary>
@@ -29,9 +31,11 @@ public static IImageProcessingContext Pad(this IImageProcessingContext source, i
2931
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
3032
public static IImageProcessingContext Pad(this IImageProcessingContext source, int width, int height, Color color)
3133
{
34+
Size size = source.GetCurrentSize();
3235
var options = new ResizeOptions
3336
{
34-
Size = new Size(width, height),
37+
// Prevent downsizing.
38+
Size = new Size(Math.Max(width, size.Width), Math.Max(height, size.Height)),
3539
Mode = ResizeMode.BoxPad,
3640
Sampler = KnownResamplers.NearestNeighbor,
3741
PadColor = color

src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,9 @@ public void ApplyTransform<TResampler>(in TResampler sampler)
6161
Rectangle destinationRectangle = this.destinationRectangle;
6262
bool compand = this.options.Compand;
6363
bool premultiplyAlpha = this.options.PremultiplyAlpha;
64-
65-
this.options.PadColor = Color.GreenYellow;
66-
64+
TPixel fillColor = this.options.PadColor.ToPixel<TPixel>();
6765
bool shouldFill = (this.options.Mode == ResizeMode.BoxPad || this.options.Mode == ResizeMode.Pad)
6866
&& this.options.PadColor != default;
69-
TPixel fillColor = this.options.PadColor.ToPixel<TPixel>();
7067

7168
// Handle resize dimensions identical to the original
7269
if (source.Width == destination.Width

src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeWorker.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ public ResizeWorker(
8080

8181
int numberOfWindowBands = ResizeHelper.CalculateResizeWorkerHeightInWindowBands(
8282
this.windowBandHeight,
83-
targetWorkingRect.Width,
83+
destWidth,
8484
workingBufferLimitHintInBytes);
8585

8686
this.workerHeight = Math.Min(this.sourceRectangle.Height, numberOfWindowBands * this.windowBandHeight);
8787

8888
this.transposedFirstPassBuffer = configuration.MemoryAllocator.Allocate2D<Vector4>(
8989
this.workerHeight,
90-
targetWorkingRect.Width,
90+
destWidth,
9191
preferContiguosImageBuffers: true,
9292
options: AllocationOptions.Clean);
9393

0 commit comments

Comments
 (0)