ImageSharp icon indicating copy to clipboard operation
ImageSharp copied to clipboard

ImageSharp sometimes add gray rectangle at the bottom right

Open laitauchocolat opened this issue 1 year ago • 9 comments

Prerequisites

  • [X] I have written a descriptive issue title
  • [X] I have verified that I am running the latest version of ImageSharp
  • [X] I have verified if the problem exist in both DEBUG and RELEASE mode
  • [X] I have searched open and closed issues to ensure it has not already been reported

ImageSharp version

3.1.0

Other ImageSharp packages and versions

3.0.1

Environment (Operating system, version and so on)

Windows 11

.NET Framework version

.NET 6

Description

On some picture, ImageSharp will add a gray rectangle at the bottom right, Original: 826862_3 Final: square

Steps to Reproduce

Download sample projet c# Replace fb.jpg with the original picture: 826862_3 try it with version 3.0.1, (no gray square) erease debug + obj and install the latest version 3.1.2 and execute, (gray square)

Images

No response

laitauchocolat avatar Jan 03 '24 16:01 laitauchocolat

@br3aker would it be possible for you to have a look at this? I thought we’d fixed it previously.

JimBobSquarePants avatar Jan 15 '24 21:01 JimBobSquarePants

I got the same thing net8.0 mango mangoSaved

I save it like this:

using var fstream = file.OpenReadStream(); // file is IFormFile (asp.net core)

var img = Image.Load(fstream);
await img.SaveAsync(filePath, new JpegEncoder { Quality = 50 });

cropping the bottom part helps avoid the problem

omuleanu avatar Jan 29 '24 20:01 omuleanu

Does the issue happen on decode or encode?

I got the same thing net8.0

What do you mean by this? Same version different target framework?

JimBobSquarePants avatar Jan 30 '24 02:01 JimBobSquarePants

@JimBobSquarePants version 3.1.2 net8.0 the image with the gray square is the result of img.SaveAsync(filePath, new JpegEncoder { Quality = 50 }); I assume this is encode.

omuleanu avatar Jan 30 '24 09:01 omuleanu

OK. Can you please encode the image as Png and let me know whether the result is the same?

JimBobSquarePants avatar Jan 30 '24 09:01 JimBobSquarePants

using await img.SaveAsPngAsync(Path.ChangeExtension(filePath, "png")); I also get the gray square, I'm also doing a clone and resize to 300x300 and that one also has the square.

2

omuleanu avatar Jan 30 '24 09:01 omuleanu

Decoder then. Will need to figure out the commit that broke it.

JimBobSquarePants avatar Jan 30 '24 12:01 JimBobSquarePants

Hm, that's strange. I'll take a look this weekend.

br3aker avatar Feb 01 '24 12:02 br3aker

Thanks @br3aker it was likely something around this. https://github.com/SixLabors/ImageSharp/pull/2516/files#diff-2ffe67fdac3f8753169905e125b8ddb27ec966025580e775f7b07e4c6f2c8d0dR215

JimBobSquarePants avatar Feb 02 '24 05:02 JimBobSquarePants

Thanks @br3aker it was likely something around this. #2516 (files)

That's actually it but fix is rather complex if we don't want to break existing logic with that fast 'DOS images'. Working on it atm.

br3aker avatar Feb 26 '24 10:02 br3aker

@br3aker I kid you not I was JUST this second writing a comment to see if you wanted me to have a look. 🤪

Thanks for helping out. Much appreciated!

JimBobSquarePants avatar Feb 26 '24 10:02 JimBobSquarePants

This also happens in Version 2.1.6. It's not an Version 3-Issue

phoebusryan avatar Mar 06 '24 07:03 phoebusryan

This also happens in Version 2.1.6. It's not an Version 3-Issue

I upgraded from 2.1.3 to 2.1.7 due to CVE-2024-27929 and am seeing the gray rectangle on certain images also.

hightechie avatar Mar 07 '24 03:03 hightechie

The same code is in both v2 and v3. Trust @br3aker in his analysis, he knows more about that decoder than anyone on the planet.

JimBobSquarePants avatar Mar 07 '24 03:03 JimBobSquarePants

Sounds good. Hope he will find a solution, soon :)

phoebusryan avatar Mar 07 '24 06:03 phoebusryan

Is there any update on this issue? It's negatively impacting us, and the workaround of cropping feels kinda hacky :-)

AndrewGretton avatar Mar 18 '24 12:03 AndrewGretton

I'll prioritize it. Stay tuned.

JimBobSquarePants avatar Mar 18 '24 12:03 JimBobSquarePants

I've got PRs open for the v3 and v4 branches. It's nearly 1am here now though so I'll see how reviews go in the morning.

JimBobSquarePants avatar Mar 18 '24 14:03 JimBobSquarePants

Thanks for the amazingly fast turnaround @JimBobSquarePants - appreciate it! Looking forward to a new version appearing on nuget soon.

AndrewGretton avatar Mar 19 '24 16:03 AndrewGretton

Hey @JimBobSquarePants - any chance of a new release on nuget 🙏 ? It beats building from source ourselves

AndrewGretton avatar Mar 26 '24 13:03 AndrewGretton

Working on it! Just gotta get one critical task done first.

JimBobSquarePants avatar Mar 27 '24 09:03 JimBobSquarePants

@JimBobSquarePants - Is there any chance of this being backported to v2? (we're still dependent on .NET Standard) I just tried upgrading to 2.8 from 2.3 (to address the two CVE's) and the gray rectangle appears with our test images. Thank you kindly if you're able to make this happen.

hightechie avatar Apr 19 '24 00:04 hightechie

If you open a PR against our 2.1.x release branch I can get one merged. We’re only backporting security releases in-house at the moment to stay on top of maintenance.

JimBobSquarePants avatar Apr 19 '24 01:04 JimBobSquarePants

If you open a PR against our 2.1.x release branch I can get one merged. We’re only backporting security releases in-house at the moment to stay on top of maintenance.

I appreciate the quick reply and certainly understand you have to prioritize your time. If I knew how to do this I absolutely would do so, I'm just not sure how to even go about attempting something like this unfortunately. Regardless, thank you for everything you do for the community here.

hightechie avatar Apr 19 '24 01:04 hightechie

Hi, I got the same issue in my project .net6.0 and the ImageSharp version is 3.1.4. I couldn't figure out if this issue fixed in 3.1.4 or for next release, anyone help?

fabercs avatar May 08 '24 15:05 fabercs

Hi, I got the same issue in my project .net6.0 and the ImageSharp version is 3.1.4. I couldn't figure out if this issue fixed in 3.1.4 or for next release, anyone help?

The fix has been released. If you are still seeing an issue, please raise a separate ticket with the image in question.

JimBobSquarePants avatar May 10 '24 11:05 JimBobSquarePants