saucecontrol / PhotoSauce

MagicScaler high-performance, high-quality image processing pipeline for .NET
http://photosauce.net/
MIT License
589 stars 49 forks source link

System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'length') #108

Closed jasonliuplanetart closed 9 months ago

jasonliuplanetart commented 1 year ago

Hi ,when i use the https://dev.azure.com/saucecontrol/PhotoSauce/_artifacts/feed/photosauce_ci in linux, version is: 0.14.0-ci223521 I get this error.

System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'length') at PhotoSauce.NativeCodecs.Libpng.PngContainer.generateIccProfile() at PhotoSauce.NativeCodecs.Libpng.PngContainer.getIccp() at PhotoSauce.NativeCodecs.Libpng.PngContainer.PhotoSauce.MagicScaler.IIccProfileSource.get_ProfileLength() at PhotoSauce.MagicScaler.Transforms.MagicTransforms.AddColorProfileReader(PipelineContext ctx) at PhotoSauce.MagicScaler.MagicImageProcessor.buildPipeline(PipelineContext ctx, Boolean closedPipeline) at PhotoSauce.MagicScaler.MagicImageProcessor.ProcessImage(Stream imgStream, Stream outStream, ProcessImageSettings settings)

Cloud you please take a look?

saucecontrol commented 1 year ago

Can you share the image? That code path is used only for PNGs using the cHRM and/or gAMA tags but no embedded color profile.

jasonliuplanetart commented 1 year ago

Thank you for your reply, unfortunately, because I got this exception in the log of the production environment, we didn't encounter it when we were debugging locally, so we couldn't get the image.

saucecontrol commented 1 year ago

Ah, ok. That code is getting re-worked as part of the BMP implementation since that decoder also needs to generate ICC profiles on the fly. The extra testing around that might reveal something.

jasonliuplanetart commented 1 year ago

Thanks,I will be looking forward to the release of the new version.

jasonliuplanetart commented 1 year ago

I also got the following exception information from our production environment, I hope it will be helpful for your test.

System.InvalidOperationException: Libpng decoder failed. bad adaptive filter value
   at PhotoSauce.NativeCodecs.Libpng.PngContainer.throwPngError(ps_png_struct* handle)
   at PhotoSauce.NativeCodecs.Libpng.PngFrame.PngPixelSource.CopyPixelsInternal(PixelArea& prc, Int32 cbStride, Int32 cbBufferSize, Byte* pbBuffer)
   at PhotoSauce.MagicScaler.Transforms.ConversionTransform.copyPixelsDirect(PixelArea& prc, Int32 cbStride, Byte* pbBuffer)
   at PhotoSauce.MagicScaler.Transforms.ConvolutionTransform`3.loadBuffer(Int32 first, Int32 lines)
   at PhotoSauce.MagicScaler.Transforms.ConvolutionTransform`3.CopyPixelsInternal(PixelArea& prc, Int32 cbStride, Int32 cbBufferSize, Byte* pbBuffer)
   at PhotoSauce.MagicScaler.Transforms.ConvolutionTransform`3.loadBuffer(Int32 first, Int32 lines)
   at PhotoSauce.MagicScaler.Transforms.ConvolutionTransform`3.CopyPixelsInternal(PixelArea& prc, Int32 cbStride, Int32 cbBufferSize, Byte* pbBuffer)
   at PhotoSauce.MagicScaler.Transforms.ConversionTransform.copyPixelsBuffered(PixelArea& prc, Int32 cbStride, Byte* pbBuffer)
   at PhotoSauce.MagicScaler.Transforms.ConversionTransform.copyPixelsDirect(PixelArea& prc, Int32 cbStride, Byte* pbBuffer)
   at PhotoSauce.MagicScaler.PixelSource.CopyPixels(PixelArea& prc, Int32 cbStride, Int32 cbBufferSize, Byte* pbBuffer)
   at PhotoSauce.MagicScaler.PixelSource.PhotoSauce.MagicScaler.IPixelSource.CopyPixels(Rectangle sourceArea, Int32 cbStride, Span`1 buffer)
   at PhotoSauce.NativeCodecs.Libpng.PngEncoder.writePixels(IPixelSource src, PixelArea area)
   at PhotoSauce.NativeCodecs.Libpng.PngEncoder.WriteFrame(IPixelSource source, IMetadataSource metadata, Rectangle sourceArea)
System.NullReferenceException: Object reference not set to an instance of an object.
   at PhotoSauce.MagicScaler.Converters.ConverterToLinear`2.Converter3X.PhotoSauce.MagicScaler.Converters.IConversionProcessor.ConvertLine(Byte* istart, Byte* ostart, IntPtr cb)
   at PhotoSauce.MagicScaler.Transforms.ConversionTransform.copyPixelsDirect(PixelArea& prc, Int32 cbStride, Byte* pbBuffer)
   at PhotoSauce.MagicScaler.PixelSource.CopyPixels(PixelArea& prc, Int32 cbStride, Int32 cbBufferSize, Byte* pbBuffer)
   at PhotoSauce.MagicScaler.Transforms.ColorMatrixTransformInternal.CopyPixelsInternal(PixelArea& prc, Int32 cbStride, Int32 cbBufferSize, Byte* pbBuffer)
   at PhotoSauce.MagicScaler.Transforms.ConversionTransform.copyPixelsBuffered(PixelArea& prc, Int32 cbStride, Byte* pbBuffer)
   at PhotoSauce.MagicScaler.Transforms.ConversionTransform.copyPixelsDirect(PixelArea& prc, Int32 cbStride, Byte* pbBuffer)
   at PhotoSauce.MagicScaler.PixelSource.CopyPixels(PixelArea& prc, Int32 cbStride, Int32 cbBufferSize, Byte* pbBuffer)
   at PhotoSauce.MagicScaler.PixelSource.PhotoSauce.MagicScaler.IPixelSource.CopyPixels(Rectangle sourceArea, Int32 cbStride, Span`1 buffer)
   at PhotoSauce.NativeCodecs.Libpng.PngEncoder.writePixels(IPixelSource src, PixelArea area)
   at PhotoSauce.NativeCodecs.Libpng.PngEncoder.WriteFrame(IPixelSource source, IMetadataSource metadata, Rectangle sourceArea)
   at PhotoSauce.MagicScaler.MagicImageProcessor.WriteOutput(PipelineContext ctx, Stream ostm)
   at PhotoSauce.MagicScaler.MagicImageProcessor.ProcessImage(Stream imgStream, Stream outStream, ProcessImageSettings settings)
System.InvalidOperationException: Libpng encoder failed. Write failed.
   at PhotoSauce.NativeCodecs.Libpng.PngEncoder.checkResult(Int32 res)
   at PhotoSauce.NativeCodecs.Libpng.PngEncoder.writePixels(IPixelSource src, PixelArea area)
   at PhotoSauce.NativeCodecs.Libpng.PngEncoder.WriteFrame(IPixelSource source, IMetadataSource metadata, Rectangle sourceArea)
   at PhotoSauce.MagicScaler.MagicImageProcessor.WriteOutput(PipelineContext ctx, Stream ostm)
   at PhotoSauce.MagicScaler.MagicImageProcessor.ProcessImage(Stream imgStream, Stream outStream, ProcessImageSettings settings)
System.InvalidOperationException: Libpng decoder failed. Not enough image data
   at PhotoSauce.NativeCodecs.Libpng.PngContainer.throwPngError(ps_png_struct* handle)
   at PhotoSauce.NativeCodecs.Libpng.PngFrame.PngPixelSource.CopyPixelsInternal(PixelArea& prc, Int32 cbStride, Int32 cbBufferSize, Byte* pbBuffer)
   at PhotoSauce.MagicScaler.Transforms.ConversionTransform.copyPixelsDirect(PixelArea& prc, Int32 cbStride, Byte* pbBuffer)
   at PhotoSauce.MagicScaler.Transforms.ConvolutionTransform`3.loadBuffer(Int32 first, Int32 lines)
   at PhotoSauce.MagicScaler.Transforms.ConvolutionTransform`3.CopyPixelsInternal(PixelArea& prc, Int32 cbStride, Int32 cbBufferSize, Byte* pbBuffer)
   at PhotoSauce.MagicScaler.PixelSource.CopyPixels(PixelArea& prc, Int32 cbStride, Int32 cbBufferSize, Byte* pbBuffer)
   at PhotoSauce.MagicScaler.Transforms.ColorMatrixTransformInternal.CopyPixelsInternal(PixelArea& prc, Int32 cbStride, Int32 cbBufferSize, Byte* pbBuffer)
   at PhotoSauce.MagicScaler.Transforms.ConvolutionTransform`3.loadBuffer(Int32 first, Int32 lines)
   at PhotoSauce.MagicScaler.Transforms.ConvolutionTransform`3.CopyPixelsInternal(PixelArea& prc, Int32 cbStride, Int32 cbBufferSize, Byte* pbBuffer)
   at PhotoSauce.MagicScaler.Transforms.ConversionTransform.copyPixelsBuffered(PixelArea& prc, Int32 cbStride, Byte* pbBuffer)
   at PhotoSauce.MagicScaler.Transforms.ConversionTransform.copyPixelsDirect(PixelArea& prc, Int32 cbStride, Byte* pbBuffer)
   at PhotoSauce.MagicScaler.PixelSource.CopyPixels(PixelArea& prc, Int32 cbStride, Int32 cbBufferSize, Byte* pbBuffer)
   at PhotoSauce.MagicScaler.PixelSource.PhotoSauce.MagicScaler.IPixelSource.CopyPixels(Rectangle sourceArea, Int32 cbStride, Span`1 buffer)
   at PhotoSauce.NativeCodecs.Libpng.PngEncoder.writePixels(IPixelSource src, PixelArea area)
   at PhotoSauce.NativeCodecs.Libpng.PngEncoder.WriteFrame(IPixelSource source, IMetadataSource metadata, Rectangle sourceArea)
   at PhotoSauce.MagicScaler.MagicImageProcessor.WriteOutput(PipelineContext ctx, Stream ostm)
   at PhotoSauce.MagicScaler.MagicImageProcessor.ProcessImage(Stream imgStream, Stream outStream, ProcessImageSettings settings)
jasonliuplanetart commented 1 year ago

I noticed that you released a new version on azure nuget on March 1st. The version we are using is still last year's version. Can this update fix the above issues?

saucecontrol commented 1 year ago

The new packages are just updates of the native libraries, which do have some small fixes but don't look to be related to any of the exceptions you've shared. Some of those appear to be usage issues, so without a reproducible test case, there won't be anything I can do about them.

saucecontrol commented 10 months ago

I just had another look through these exceptions, and it looks like they're the same as reported in https://github.com/saucecontrol/PhotoSauce/issues/140

There's a new set of packages on the CI feed that should fix all of the decoder exceptions. I still have no clue on the one encoder exception you included, but I have improved handling of Stream-related exceptions, which I believe should be the only failures possible on write. Those are now properly re-thrown Linux.

jasonliuplanetart commented 9 months ago

Sorry for the delayed response. After upgrading to the latest version of the package, we not see this exception in the production environment. Thank you for your help. I will close this issue.