SixLabors / ImageSharp

:camera: A modern, cross-platform, 2D Graphics library for .NET
https://sixlabors.com/products/imagesharp/
Other
7.41k stars 852 forks source link

.Net 5.0 RC-1 breaks ImageSharp #1356

Closed lofcz closed 4 years ago

lofcz commented 4 years ago

Prerequisites

Description

I've encountered a strange bug when mutating images after migrating mvc app from net fw48 to net5 rc1. I've swapped to async image handling. Steps I do (async action on a controller):

1) await HttpContext.Request.ReadFormAsync()
2) Image<Rgba32> img = Image.Load<Rgba32>([first image from form].OpenReadStream(), out IImageFormat imgFormat);
3) await img.SaveAsync("some path"); // saves the image correctly
4) img.Mutate(x => x.Resize(w, h, s)); // thumbnail; used Bicubic, tried Lancoz3 to check if that could be the problem
5) await img.SaveAsync("thumbnail path");

// also tried alternative
5) await using FileStream stream = System.IO.File.Create("some path");
6) await img.SaveAsync(stream, imgFormat);

Extremely frustrating is that this is happening only on production, not on my local machine. I've tried to use another sampler and use latest dev build of ImageSharp, neither helped. In each and every case the first half of an image is mutated correctly, while the other is either blank or filled with artifacts. I'm clueless about how should I move forward, the only option so far would be to go back to sync processing of images which I'd very much like to avoid. Attaching some test images:

Saved thumbnail 1:

a8f3fce0-c6ec-4e4b-a304-ae381301f9ef_thumbnail (1)

Saved non-mutated image 1:

a8f3fce0-c6ec-4e4b-a304-ae381301f9ef

Saved thumbnail 2:

803238f6-8248-4df7-ac73-a0f36840295a_thumbnail

Saved non-mutated image 2:

803238f6-8248-4df7-ac73-a0f36840295a

Saved thumbnail 3:

bc54f22d-1ae8-4135-ad38-3f3e761767f4_thumbnail

Saved non-mutated image 3:

bc54f22d-1ae8-4135-ad38-3f3e761767f4

System Configuration

ImageSharp version:

klogeaage commented 4 years ago

The difference between the 2 skus mentioned by @klogeaage is not just memory size but also CPU constraints. Based on the memory looks like we are talking about a 'B1' scale machine and a 'P2V2' the difference on those machines is not just memory by a move from approx. 1 cpu to something more like 4.

Yes, indeed, you have deducted it absolutely right. So glad we are narrowing this down to something meaningful.

tannergooding commented 4 years ago

We've got some people on the runtime team that are going to look further: https://github.com/dotnet/runtime/issues/42912

For future reference, we don't strictly need a minimal repro on dotnet/runtime for an issue to be opened. We'd much rather get an issue opened than not see it all, especially when we are this late in the release cycle 😄

This might be a more complex runtime bug, in which case finding a minimal repro might be difficult or impossible.

tocsoft commented 4 years ago

@tannergooding Oh thanks for raising that I was planning to it myself one I had reduced it a little more.

tredition commented 4 years ago

A short info: It seems that it doesn't have to do anything with cropping, resizing etc. Just tried out: Simply open a jpg image and save it -> Broken in an Azure App Service (Windows):

            var image = Image.Load<Rgba32>(filename);
            image.Save(filename);
tocsoft commented 4 years ago

it definitely the JPEG decoder that's failing I've updated my reproduction repo to verify that's the case. https://github.com/tocsoft/Net5CorruptingImageSharp

brianpopow commented 4 years ago

good news: It looks like with .Net 5.0 RC-2 this issue will be fixed!

Sergio0694 commented 4 years ago

@JimBobSquarePants .NET 5 RC2 is out! 🚀🚀🚀

brianpopow commented 4 years ago

I have tested this issue again with RC2 and can confirm the issue is gone. I will close the issue now.

Thanks to all who helped tracking down this issue!