Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

none-progressive jpeg with missing EOI marker throws EOFException #83

Closed
vaindil opened this issue Jan 18, 2017 · 4 comments · Fixed by #85
Closed

none-progressive jpeg with missing EOI marker throws EOFException #83

vaindil opened this issue Jan 18, 2017 · 4 comments · Fixed by #85

Comments

@vaindil
Copy link

vaindil commented Jan 18, 2017

I'm on 1.0.0-alpha1-00049, .NET Core 1.1.0. An image I'm testing with (attached) is throwing the below exception when I call var image = new Image(stream);. All other images I've tested work properly, but I'm not sure what's happening with this one.

(In case GitHub altered it, I've uploaded the image here.)

Exception:

EOFException: Exception of type 'ImageSharp.Formats.JpegDecoderCore+EOFException' was thrown.

My code:

[HttpPost]
public async Task<IActionResult> Upload(IFormFile image)
{
    using (var stream = new MemoryStream())
    {
        await image.CopyToAsync(stream);

        // image verification, stream variable is not touched/used

        stream.Seek(0, SeekOrigin.Begin);

        StripExif(stream);

        // do stuff
    }

    return Ok();
}

public static void StripExif(Stream stream)
{
    // exception thrown here
    var image = new Image(stream);
    
    stream.Seek(0, SeekOrigin.Begin);

    if (image.ExifProfile == null)
        return;

    // a ton of these follow
    image.ExifProfile.RemoveValue(ExifTag.GPSLatitude);

    // ...

    image.Save(stream);
    stream.Seek(0, SeekOrigin.Begin);
}

Beginning of stack trace:

ImageSharp.Formats.JpegDecoderCore+EOFException: Exception of type 'ImageSharp.Formats.JpegDecoderCore+EOFException' was thrown.
   at ImageSharp.Formats.JpegDecoderCore.Decode[TColor](Image`1 image, Stream stream, Boolean configOnly)
   at ImageSharp.Formats.JpegDecoder.Decode[TColor](Image`1 image, Stream stream)
   at ImageSharp.Image`1.Decode(Stream stream)
   at ImageSharp.Image`1.Load(Stream stream)
   at [removed].StripExif(Stream stream) in [removed]\UploadHelpers.cs:line 39
   at [removed].ImagesController.<Upload>d__5.MoveNext() in [removed]\ImagesController.cs:line 66
@vaindil
Copy link
Author

vaindil commented Jan 18, 2017

Shoot, I just saw #18, not sure how I missed it. This is probably a duplicate.

@JimBobSquarePants
Copy link
Member

Thanks yeah, a duplicate. Let's close this.

@tocsoft tocsoft changed the title Exception of type 'ImageSharp.Formats.JpegDecoderCore+EOFException' was thrown none-progressive jpeg with missing EOI marker throws EOFException Jan 21, 2017
@tocsoft
Copy link
Member

tocsoft commented Jan 21, 2017

reopening as this is slightly different to the other issue... this is a none-progressive image the other is progressive

@tocsoft tocsoft reopened this Jan 21, 2017
@tocsoft
Copy link
Member

tocsoft commented Jan 21, 2017

@vaindil The issue effecting your image has now been fixed if you upgrade ImageSharp.Formats.Jpeg to latest you should get the fix. (Fix landed in ImageSharp.Formats.Jpeg version 1.0.0-alpha1-00045)

Note this only fixes the issue for none-progressive jpegs so depending on what images you have uploaded it might not work for all of them but it should help some. If you get any more that you can still open locally then it more than likely going to be related to issue #18.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants