Browse Source

Merge pull request #85 from JimBobSquarePants/missing-eoi

Load none-progressive images with missing EOI markers.
pull/97/head
Scott Williams 9 years ago
committed by GitHub
parent
commit
0ea075bd6e
  1. 13
      src/ImageSharp.Formats.Jpeg/JpegDecoderCore.cs
  2. 40
      tests/ImageSharp.Tests/Formats/Jpg/BadEofJpegTests.cs
  3. 1
      tests/ImageSharp.Tests/TestImages.cs
  4. BIN
      tests/ImageSharp.Tests/TestImages/Formats/Jpg/badeof.jpg

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

@ -187,7 +187,10 @@ namespace ImageSharp.Formats
} }
// Process the remaining segments until the End Of Image marker. // Process the remaining segments until the End Of Image marker.
while (true) bool processBytes = true;
// we can't currently short circute progressive images so don't try.
while (processBytes)
{ {
this.ReadFull(this.Temp, 0, 2); this.ReadFull(this.Temp, 0, 2);
while (this.Temp[0] != 0xff) while (this.Temp[0] != 0xff)
@ -294,7 +297,15 @@ namespace ImageSharp.Formats
return; 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.
this.ProcessStartOfScan(remaining); this.ProcessStartOfScan(remaining);
if (!this.IsProgressive)
{
// if this is not a progressive image we can stop processing bytes as we now have the image data.
processBytes = false;
}
break; break;
case JpegConstants.Markers.DRI: case JpegConstants.Markers.DRI:
if (configOnly) if (configOnly)

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

@ -0,0 +1,40 @@
// <copyright file="JpegTests.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using ImageSharp.Formats;
using Xunit;
using Xunit.Abstractions;
// ReSharper disable InconsistentNaming
namespace ImageSharp.Tests
{
using System.Numerics;
using ImageSharp.Formats.Jpg;
using ImageSharp.Processing;
public class BadEOFJpegTests : MeasureFixture
{
public BadEOFJpegTests(ITestOutputHelper output)
: base(output)
{
}
[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");
}
}
}

1
tests/ImageSharp.Tests/TestImages.cs

@ -51,6 +51,7 @@ namespace ImageSharp.Tests
public const string Festzug = "Jpg/Festzug.jpg"; public const string Festzug = "Jpg/Festzug.jpg";
public const string Hiyamugi = "Jpg/Hiyamugi.jpg"; public const string Hiyamugi = "Jpg/Hiyamugi.jpg";
public const string BadEOF = "Jpg/badeof.jpg";
public const string Snake = "Jpg/Snake.jpg"; public const string Snake = "Jpg/Snake.jpg";
public const string Lake = "Jpg/Lake.jpg"; public const string Lake = "Jpg/Lake.jpg";

BIN
tests/ImageSharp.Tests/TestImages/Formats/Jpg/badeof.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Loading…
Cancel
Save