Skip to content

Commit 9816ca4

Browse files
Merge pull request #2770 from SixLabors/af/backport-2759-2.1.x
Backport 2759 to 2.1.x
2 parents a1f2879 + b33d666 commit 9816ca4

File tree

15 files changed

+564
-278
lines changed

15 files changed

+564
-278
lines changed

src/ImageSharp/Formats/Gif/GifDecoder.cs

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ public sealed class GifDecoder : IImageDecoder, IGifDecoderOptions, IImageInfoDe
2323
/// </summary>
2424
public FrameDecodingMode DecodingMode { get; set; } = FrameDecodingMode.All;
2525

26+
/// <summary>
27+
/// Gets or sets the maximum number of gif frames.
28+
/// </summary>
29+
public uint MaxFrames { get; set; } = uint.MaxValue;
30+
2631
/// <inheritdoc/>
2732
public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream, CancellationToken cancellationToken)
2833
where TPixel : unmanaged, IPixel<TPixel>

src/ImageSharp/Formats/Gif/GifDecoderCore.cs

+284-181
Large diffs are not rendered by default.

src/ImageSharp/Formats/Gif/GifThrowHelper.cs

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0.
33

44
using System;
5+
using System.Diagnostics.CodeAnalysis;
56
using System.Runtime.CompilerServices;
67

78
namespace SixLabors.ImageSharp.Formats.Gif
@@ -24,5 +25,11 @@ public static void ThrowInvalidImageContentException(string errorMessage)
2425
/// if no inner exception is specified.</param>
2526
[MethodImpl(InliningOptions.ColdPath)]
2627
public static void ThrowInvalidImageContentException(string errorMessage, Exception innerException) => throw new InvalidImageContentException(errorMessage, innerException);
28+
29+
[MethodImpl(InliningOptions.ColdPath)]
30+
public static void ThrowNoHeader() => throw new InvalidImageContentException("Gif image does not contain a Logical Screen Descriptor.");
31+
32+
[MethodImpl(InliningOptions.ColdPath)]
33+
public static void ThrowNoData() => throw new InvalidImageContentException("Unable to read Gif image data");
2734
}
2835
}

src/ImageSharp/Formats/Gif/IGifDecoderOptions.cs

+5
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,10 @@ internal interface IGifDecoderOptions
1919
/// Gets the decoding mode for multi-frame images.
2020
/// </summary>
2121
FrameDecodingMode DecodingMode { get; }
22+
23+
/// <summary>
24+
/// Gets or sets the maximum number of gif frames.
25+
/// </summary>
26+
uint MaxFrames { get; set; }
2227
}
2328
}

0 commit comments

Comments
 (0)