diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs
index 7fc3f0d97a..483c22a39d 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs
@@ -1,4 +1,4 @@
-// Copyright (c) Six Labors and contributors.
+// Copyright (c) Six Labors and contributors.
// Licensed under the GNU Affero General Public License, Version 3.
using System;
@@ -28,12 +28,12 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
///
/// Gets or sets the number of scanlines within the frame.
///
- public short Scanlines { get; set; }
+ public int Scanlines { get; set; }
///
/// Gets or sets the number of samples per scanline.
///
- public short SamplesPerLine { get; set; }
+ public int SamplesPerLine { get; set; }
///
/// Gets or sets the number of components within a frame. In progressive frames this value can range from only 1 to 4.
@@ -105,4 +105,4 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
index a754bfd2e7..e61ca326aa 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
@@ -841,8 +841,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
Extended = frameMarker.Marker == JpegConstants.Markers.SOF1,
Progressive = frameMarker.Marker == JpegConstants.Markers.SOF2,
Precision = this.temp[0],
- Scanlines = (short)((this.temp[1] << 8) | this.temp[2]),
- SamplesPerLine = (short)((this.temp[3] << 8) | this.temp[4]),
+ Scanlines = (this.temp[1] << 8) | this.temp[2],
+ SamplesPerLine = (this.temp[3] << 8) | this.temp[4],
ComponentCount = this.temp[5]
};
diff --git a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeHelper.cs b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeHelper.cs
index 6066efd1cd..aa5c80b76b 100644
--- a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeHelper.cs
+++ b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeHelper.cs
@@ -72,7 +72,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
// case ResizeMode.Stretch:
default:
- return (new Size(width, height), new Rectangle(0, 0, width, height));
+ return (new Size(Sanitize(width), Sanitize(height)), new Rectangle(0, 0, Sanitize(width), Sanitize(height)));
}
}
@@ -143,7 +143,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
}
// Target image width and height can be different to the rectangle width and height.
- return (new Size(width, height), new Rectangle(targetX, targetY, targetWidth, targetHeight));
+ return (new Size(Sanitize(width), Sanitize(height)), new Rectangle(targetX, targetY, Sanitize(targetWidth), Sanitize(targetHeight)));
}
// Switch to pad mode to downscale and calculate from there.
@@ -253,7 +253,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
}
// Target image width and height can be different to the rectangle width and height.
- return (new Size(width, height), new Rectangle(targetX, targetY, targetWidth, targetHeight));
+ return (new Size(Sanitize(width), Sanitize(height)), new Rectangle(targetX, targetY, Sanitize(targetWidth), Sanitize(targetHeight)));
}
private static (Size, Rectangle) CalculateMaxRectangle(
@@ -282,7 +282,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
}
// Replace the size to match the rectangle.
- return (new Size(targetWidth, targetHeight), new Rectangle(0, 0, targetWidth, targetHeight));
+ return (new Size(Sanitize(targetWidth), Sanitize(targetHeight)), new Rectangle(0, 0, Sanitize(targetWidth), Sanitize(targetHeight)));
}
private static (Size, Rectangle) CalculateMinRectangle(
@@ -330,7 +330,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
}
// Replace the size to match the rectangle.
- return (new Size(targetWidth, targetHeight), new Rectangle(0, 0, targetWidth, targetHeight));
+ return (new Size(Sanitize(targetWidth), Sanitize(targetHeight)), new Rectangle(0, 0, Sanitize(targetWidth), Sanitize(targetHeight)));
}
private static (Size, Rectangle) CalculatePadRectangle(
@@ -398,7 +398,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
}
// Target image width and height can be different to the rectangle width and height.
- return (new Size(width, height), new Rectangle(targetX, targetY, targetWidth, targetHeight));
+ return (new Size(Sanitize(width), Sanitize(height)), new Rectangle(targetX, targetY, Sanitize(targetWidth), Sanitize(targetHeight)));
}
private static (Size, Rectangle) CalculateManualRectangle(
@@ -419,9 +419,11 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
int targetHeight = targetRectangle.Height > 0 ? targetRectangle.Height : height;
// Target image width and height can be different to the rectangle width and height.
- return (new Size(width, height), new Rectangle(targetX, targetY, targetWidth, targetHeight));
+ return (new Size(Sanitize(width), Sanitize(height)), new Rectangle(targetX, targetY, Sanitize(targetWidth), Sanitize(targetHeight)));
}
private static void ThrowInvalid(string message) => throw new InvalidOperationException(message);
+
+ private static int Sanitize(int input) => Math.Max(1, input);
}
}
diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs
index aec0d2a1f6..5feb8e9f07 100644
--- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs
+++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs
@@ -605,5 +605,21 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
image.Mutate(x => x.Resize(image.Width / 2, image.Height / 2));
}
}
+
+ [Fact]
+ public void Issue1195()
+ {
+ using (var image = new Image(2, 300))
+ {
+ var size = new Size(50, 50);
+ image.Mutate(x => x
+ .Resize(
+ new ResizeOptions
+ {
+ Size = size,
+ Mode = ResizeMode.Max
+ }));
+ }
+ }
}
}