Skip to content

Commit a9fa258

Browse files
committed
Also check the length of a quantum array.
1 parent 604c6f4 commit a9fa258

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/Magick.NET/Pixels/PixelCollection.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,15 @@ public virtual void SetPixels(QuantumType[] values)
223223

224224
internal QuantumType[]? GetAreaUnchecked(int x, int y, uint width, uint height)
225225
{
226+
var length = width * height * (long)Image.ChannelCount;
227+
if (length > int.MaxValue)
228+
throw new InvalidOperationException("The resulting array is too large.");
229+
226230
var pixels = NativeInstance.GetArea(x, y, width, height);
227231
if (pixels == IntPtr.Zero)
228232
throw new InvalidOperationException("Image contains no pixel data.");
229233

230-
var length = width * height * Image.ChannelCount;
231-
return QuantumConverter.ToArray(pixels, length);
234+
return QuantumConverter.ToArray(pixels, (int)length);
232235
}
233236

234237
internal void SetPixelUnchecked(int x, int y, QuantumType[] value)

0 commit comments

Comments
 (0)