SixLabors / ImageSharp

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

Relaxed handle of corrupt png files #2589

Closed svenclaesson closed 9 months ago

svenclaesson commented 9 months ago

Prerequisites

Description

WIP support for handing truncated png files

Implementing an option for PngDecoder, IgnoreCrcErrors Tried it a bit but got stuck by the fact that IDAT and IEND is considered critical chunks and found no way of ignoring that fact if the file is truncated, IDAT is cut off and IEND is missing.

This file is truncated and i'm trying to get a partial result converted as libpng (chrome) and WIC can do. 280752616-57c5e277-a472-4f13-98f0-a2a238c0fe28

Maybe you have some pointers for me

See https://github.com/SixLabors/ImageSharp/issues/2570

CLAassistant commented 9 months ago

CLA assistant check
All committers have signed the CLA.

JimBobSquarePants commented 9 months ago

@svenclaesson could you please explicitly invite me to contribute to your fork. I need to add the test image from above and due to a quirk in Git LFS permissions with GitHub I cannot push any images to your fork without being invited.

@dlemstra is there a way to get the Magick decoder to break on adaptive filter errors? When I try to use your decoder as a reference for this file the following exception is thrown.

ImageMagick.MagickCoderErrorException : bad adaptive filter value `' @ error/png.c/MagickPNGErrorHandler/1716
JimBobSquarePants commented 9 months ago

Thanks for the invite. @svenclaesson

I've now reworked the decoder to allow granular control of CRC checking and also allow us to decode the provided image.

Decode_InvalidDataChunkCrc_IgnoreCrcErrors_Rgba32_Issue_2589

svenclaesson commented 9 months ago

Thanks for working on this