Browse Source

prevent progressive images breaking.

top progressive images from shorting the loop as they break if you do.
af/merge-core
Scott Williams 9 years ago
parent
commit
c329941f97
  1. 22
      src/ImageSharp.Formats.Jpeg/JpegDecoderCore.cs
  2. 2
      tests/ImageSharp.Tests/Formats/Jpg/BadEofJpegTests.cs

22
src/ImageSharp.Formats.Jpeg/JpegDecoderCore.cs

@ -80,14 +80,9 @@ namespace ImageSharp.Formats
private YCbCrImage ycbcrImage;
/// <summary>
/// The MCU target
/// The MCU counter
/// </summary>
private int mcuTarget;
/// <summary>
/// The MCUs processed
/// </summary>
private int mcusProcessed;
private int mcuCounter;
/// <summary>
/// Initializes a new instance of the <see cref="JpegDecoderCore" /> class.
@ -197,7 +192,10 @@ namespace ImageSharp.Formats
}
// Process the remaining segments until the End Of Image marker.
while (this.mcuTarget < 1 || this.mcuTarget != this.mcusProcessed)
bool mcuSet = false;
// we can't currently short circute progressive images so don't try.
while (this.IsProgressive || !mcuSet || this.mcuCounter > 0)
{
this.ReadFull(this.Temp, 0, 2);
while (this.Temp[0] != 0xff)
@ -304,6 +302,9 @@ namespace ImageSharp.Formats
return;
}
// when this is a progressive image this gets called a number of times
// need to know how many times this should be called in total.
mcuSet = true;
this.ProcessStartOfScan(remaining);
break;
case JpegConstants.Markers.DRI:
@ -874,7 +875,6 @@ namespace ImageSharp.Formats
/// <param name="myy">The vertical MCU count</param>
private void MakeImage(int mxx, int myy)
{
this.mcuTarget = mxx * myy;
if (this.grayImage.IsInitialized || this.ycbcrImage != null)
{
return;
@ -1406,7 +1406,9 @@ namespace ImageSharp.Formats
JpegScanDecoder.Init(&scan, this, remaining);
this.Bits = default(Bits);
this.MakeImage(scan.XNumberOfMCUs, scan.YNumberOfMCUs);
this.mcusProcessed += scan.ProcessBlocks(this);
this.mcuCounter = scan.XNumberOfMCUs * scan.YNumberOfMCUs;
this.mcuCounter -= scan.ProcessBlocks(this);
}
/// <summary>

2
tests/ImageSharp.Tests/Formats/Jpg/BadEofJpegTests.cs

@ -28,11 +28,13 @@ namespace ImageSharp.Tests
[Theory]
[WithFile(TestImages.Jpeg.BadEOF, PixelTypes.Color)]
[WithFile(TestImages.Jpeg.Progress, PixelTypes.Color)]
public void LoadImage<TColor>(TestImageProvider<TColor> provider)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
var image = provider.GetImage();
Assert.NotNull(image);
provider.Utility.SaveTestOutputFile(image, "bmp");
}
}
}
Loading…
Cancel
Save