Browse Source

Merge branch 'master' into js/affine-transforms

pull/386/head
James Jackson-South 8 years ago
committed by GitHub
parent
commit
33ebe21999
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      src/ImageSharp/Formats/Gif/GifDecoderCore.cs
  2. 24
      tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs
  3. 7
      tests/ImageSharp.Tests/TestImages.cs
  4. BIN
      tests/Images/Input/Gif/issues/issue403_baddescriptorwidth.gif
  5. BIN
      tests/Images/Input/Gif/issues/issue405_badappextlength252-2.gif
  6. BIN
      tests/Images/Input/Gif/issues/issue405_badappextlength252.gif

12
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;
}
}
@ -438,7 +443,8 @@ namespace SixLabors.ImageSharp.Formats.Gif
var rgba = new Rgba32(0, 0, 0, 255);
for (int x = descriptor.Left; x < descriptor.Left + descriptor.Width; x++)
// #403 The left + width value can be larger than the image width
for (int x = descriptor.Left; x < descriptor.Left + descriptor.Width && x < rowSpan.Length; x++)
{
int index = indices[i];

24
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,27 @@ namespace SixLabors.ImageSharp.Tests
}
}
}
[Theory]
[WithFileCollection(nameof(BadAppExtFiles), PixelTypes.Rgba32)]
public void DecodeBadApplicationExtensionLength<TPixel>(TestImageProvider<TPixel> imageProvider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = imageProvider.GetImage())
{
imageProvider.Utility.SaveTestOutputFile(image, "bmp");
}
}
[Theory]
[WithFile(TestImages.Gif.Issues.BadDescriptorWidth, PixelTypes.Rgba32)]
public void DecodeBadDescriptorDimensionsLength<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
provider.Utility.SaveTestOutputFile(image, "bmp");
}
}
}
}

7
tests/ImageSharp.Tests/TestImages.cs

@ -157,6 +157,13 @@ 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 const string BadDescriptorWidth = "Gif/issues/issue403_baddescriptorwidth.gif";
}
public static readonly string[] All = { Rings, Giphy, Cheers, Trans, Kumin };
}
}

BIN
tests/Images/Input/Gif/issues/issue403_baddescriptorwidth.gif

Binary file not shown.

After

Width:  |  Height:  |  Size: 691 KiB

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Loading…
Cancel
Save