Skip to content

Commit edff37d

Browse files
Merge pull request #1532 from SixLabors/js/fix-1530
Sanitize Gif descriptor bounds.
2 parents 7dfea13 + ba115e1 commit edff37d

File tree

5 files changed

+16
-2
lines changed

5 files changed

+16
-2
lines changed

src/ImageSharp/Formats/Gif/GifDecoderCore.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,8 @@ private void RestoreToBackground<TPixel>(ImageFrame<TPixel> frame)
535535
return;
536536
}
537537

538-
Buffer2DRegion<TPixel> pixelRegion = frame.PixelBuffer.GetRegion(this.restoreArea.Value);
538+
var interest = Rectangle.Intersect(frame.Bounds(), this.restoreArea.Value);
539+
Buffer2DRegion<TPixel> pixelRegion = frame.PixelBuffer.GetRegion(interest);
539540
pixelRegion.Clear();
540541

541542
this.restoreArea = null;

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,17 @@ public void CanDecodeIntermingledImages()
171171
}
172172
}
173173

174+
// https://github.com/SixLabors/ImageSharp/issues/1503
175+
[Theory]
176+
[WithFile(TestImages.Gif.Issues.Issue1530, PixelTypes.Rgba32)]
177+
public void Issue1530_BadDescriptorDimensions<TPixel>(TestImageProvider<TPixel> provider)
178+
where TPixel : unmanaged, IPixel<TPixel>
179+
{
180+
using Image<TPixel> image = provider.GetImage();
181+
image.DebugSaveMultiFrame(provider);
182+
image.CompareToReferenceOutputMultiFrame(provider, ImageComparer.Exact);
183+
}
184+
174185
// https://github.com/SixLabors/ImageSharp/issues/405
175186
[Theory]
176187
[WithFile(TestImages.Gif.Issues.BadAppExtLength, PixelTypes.Rgba32)]
@@ -181,6 +192,7 @@ public void Issue405_BadApplicationExtensionBlockLength<TPixel>(TestImageProvide
181192
using (Image<TPixel> image = provider.GetImage())
182193
{
183194
image.DebugSave(provider);
195+
184196
image.CompareFirstFrameToReferenceOutput(ImageComparer.Exact, provider);
185197
}
186198
}

tests/ImageSharp.Tests/TestImages.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ public static class Issues
416416
public const string BadAppExtLength_2 = "Gif/issues/issue405_badappextlength252-2.gif";
417417
public const string BadDescriptorWidth = "Gif/issues/issue403_baddescriptorwidth.gif";
418418
public const string Issue1505 = "Gif/issues/issue1505_argumentoutofrange.png";
419+
public const string Issue1530 = "Gif/issues/issue1530.gif";
419420
}
420421

421422
public static readonly string[] All = { Rings, Giphy, Cheers, Trans, Kumin, Leo, Ratio4x1, Ratio1x4 };
1.76 MB
Loading

0 commit comments

Comments
 (0)