Browse Source

Merge pull request #2971 from SixLabors/js/backport-v2-fix-2953

Backport V2 - GIF: Check for end of stream when reading comments.
pull/2985/head v2.1.11
James Jackson-South 6 months ago
committed by GitHub
parent
commit
cb115c2293
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 9
      Directory.Build.props
  2. 5
      src/ImageSharp/Formats/Gif/GifDecoderCore.cs
  3. 33
      tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs
  4. 1
      tests/ImageSharp.Tests/TestImages.cs
  5. 3
      tests/Images/Input/Gif/issues/issue_2953.gif

9
Directory.Build.props

@ -33,4 +33,13 @@
<PropertyGroup Condition="$(Configuration.StartsWith('Release')) == true">
<Optimize>true</Optimize>
</PropertyGroup>
<!-- Required restore feeds. -->
<PropertyGroup>
<RestoreSources>
https://api.nuget.org/v3/index.json;
https://f.feedz.io/sixlabors/sixlabors/nuget/index.json;
https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json;
</RestoreSources>
</PropertyGroup>
</Project>

5
src/ImageSharp/Formats/Gif/GifDecoderCore.cs

@ -402,6 +402,11 @@ namespace SixLabors.ImageSharp.Formats.Gif
GifThrowHelper.ThrowInvalidImageContentException($"Gif comment length '{length}' exceeds max '{GifConstants.MaxCommentSubBlockLength}' of a comment data block");
}
if (length == -1)
{
GifThrowHelper.ThrowInvalidImageContentException("Unexpected end of stream while reading gif comment");
}
if (this.skipMetadata)
{
stream.Seek(length, SeekOrigin.Current);

33
tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs

@ -183,16 +183,16 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif
image.CompareToReferenceOutputMultiFrame(provider, ImageComparer.Exact);
}
// https://github.com/SixLabors/ImageSharp/issues/2758
[Theory]
[WithFile(TestImages.Gif.Issues.Issue2758, PixelTypes.Rgba32)]
public void Issue2758_BadDescriptorDimensions<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage();
image.DebugSaveMultiFrame(provider);
image.CompareToReferenceOutputMultiFrame(provider, ImageComparer.Exact);
}
// https://github.com/SixLabors/ImageSharp/issues/2758
[Theory]
[WithFile(TestImages.Gif.Issues.Issue2758, PixelTypes.Rgba32)]
public void Issue2758_BadDescriptorDimensions<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage();
image.DebugSaveMultiFrame(provider);
image.CompareToReferenceOutputMultiFrame(provider, ImageComparer.Exact);
}
// https://github.com/SixLabors/ImageSharp/issues/405
[Theory]
@ -329,5 +329,18 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif
image.DebugSaveMultiFrame(provider);
image.CompareToReferenceOutputMultiFrame(provider, ImageComparer.Exact);
}
// https://github.com/SixLabors/ImageSharp/issues/2953
[Theory]
[WithFile(TestImages.Gif.Issues.Issue2953, PixelTypes.Rgba32)]
public void Issue2953<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
// We should throw a InvalidImageContentException when trying to identify or load an invalid GIF file.
var testFile = TestFile.Create(provider.SourceFileOrDescription);
Assert.Throws<InvalidImageContentException>(() => Image.Identify(testFile.FullPath));
Assert.Throws<InvalidImageContentException>(() => Image.Load(testFile.FullPath));
}
}
}

1
tests/ImageSharp.Tests/TestImages.cs

@ -468,6 +468,7 @@ namespace SixLabors.ImageSharp.Tests
public const string Issue2758 = "Gif/issues/issue_2758.gif";
public const string Issue2859_A = "Gif/issues/issue_2859_A.gif";
public const string Issue2859_B = "Gif/issues/issue_2859_B.gif";
public const string Issue2953 = "Gif/issues/issue_2953.gif";
}
public static readonly string[] All = { Rings, Giphy, Cheers, Trans, Kumin, Leo, Ratio4x1, Ratio1x4 };

3
tests/Images/Input/Gif/issues/issue_2953.gif

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:4fa4a002b264a41677cc10f115f3572111852993a53ee8cea5f4ec0bf8dec195
size 40
Loading…
Cancel
Save