Browse Source

Fix #405

af/merge-core
James Jackson-South 8 years ago
parent
commit
e884bc3490
  1. 9
      src/ImageSharp/Formats/Gif/GifDecoderCore.cs
  2. 13
      tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs
  3. 6
      tests/ImageSharp.Tests/TestImages.cs
  4. 3
      tests/Images/Input/Gif/issues/issue405_badappextlength252-2.gif
  5. 3
      tests/Images/Input/Gif/issues/issue405_badappextlength252.gif

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

@ -155,10 +155,15 @@ namespace SixLabors.ImageSharp.Formats.Gif
this.ReadComments();
break;
case GifConstants.ApplicationExtensionLabel:
this.Skip(12); // No need to read.
// The application extension length should be 11 but we've got test images that incorrectly
// set this to 252.
int appLength = stream.ReadByte();
this.Skip(appLength); // No need to read.
break;
case GifConstants.PlainTextLabel:
this.Skip(13); // Not supported by any known decoder.
int plainLength = stream.ReadByte();
this.Skip(plainLength); // Not supported by any known decoder.
break;
}
}

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

@ -18,6 +18,7 @@ namespace SixLabors.ImageSharp.Tests
public static readonly string[] TestFiles = { TestImages.Gif.Giphy, TestImages.Gif.Rings, TestImages.Gif.Trans };
public static readonly string[] BadAppExtFiles = { TestImages.Gif.Issues.BadAppExtLength, TestImages.Gif.Issues.BadAppExtLength_2 };
[Theory]
[WithFileCollection(nameof(TestFiles), PixelTypes)]
@ -30,6 +31,7 @@ namespace SixLabors.ImageSharp.Tests
imageProvider.Utility.SaveTestOutputFile(image, "gif");
}
}
[Theory]
[WithFileCollection(nameof(TestFiles), PixelTypes)]
public void DecodeResizeAndSave<TPixel>(TestImageProvider<TPixel> imageProvider)
@ -132,5 +134,16 @@ namespace SixLabors.ImageSharp.Tests
}
}
}
[Theory]
[WithFileCollection(nameof(BadAppExtFiles), PixelTypes)]
public void DecodeBadApplicationExtensionLength<TPixel>(TestImageProvider<TPixel> imageProvider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = imageProvider.GetImage())
{
imageProvider.Utility.SaveTestOutputFile(image, "bmp");
}
}
}
}

6
tests/ImageSharp.Tests/TestImages.cs

@ -157,6 +157,12 @@ namespace SixLabors.ImageSharp.Tests
public const string Trans = "Gif/trans.gif";
public const string Kumin = "Gif/kumin.gif";
public class Issues
{
public const string BadAppExtLength = "Gif/issues/issue405_badappextlength252.gif";
public const string BadAppExtLength_2 = "Gif/issues/issue405_badappextlength252-2.gif";
}
public static readonly string[] All = { Rings, Giphy, Cheers, Trans, Kumin };
}
}

3
tests/Images/Input/Gif/issues/issue405_badappextlength252-2.gif

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:151d394c7c57a1696fedc32116514b667ad70c4a2c7d34db7c489c17d5755eed
size 24724

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

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