Repository navigation
Decoding malformed iPhone generated PNG throws 'Bad compression method for ZLIB header: cmf=237' #410
Description
Activity
Hi @zeus82
Thanks for the detail and the input image. It turns out that image is not a valid png.
http://iphonedevwiki.net/index.php/CgBI_file_format
There's quite a few differences between the format
- extra critical chunk (CgBI)
- byteswapped (RGBA -> BGRA) pixel data, presumably for high-speed direct blitting to the framebuffer
- zlib header, footer, and CRC removed from the IDAT chunk
- premultiplied alpha (color' = color * alpha / 255)
@antonfirsov @tocsoft @dlemstra
Theoretically it looks like we could potentially handle these changes with some updates to our decoder based on the following, it looks like a lot of work though for all our different color types:
http://www.axelbrz.com.ar/?mod=iphone-png-images-normalizer
I don't know if we should attempt this for V1 though. What do you think?
seeing as chrome doesn't seem to even seem to render it then i'm inclined to think we should defiantly push it past v1 and even then see how much of an issue its causing in the future and make a another call then.
Reacted by James Jackson-SouthHa! Doesn't it! I only have Edge installed at the mo cos I had to get my laptop replaced. That renders something but it ain't pretty. Yeah let's leave it for now then.
Only Windows + GDI based decoders seem do decode it properly. I consider this issue as low-priority one, definitely not a show-stopper for V 1.0.
Reacted by James Jackson-SouthOk, have moved it to futures. Gonna do a little cleanup in the png decoder around the zlib headers to remove an allocation I saw that we don't need anyway.
I would detect this specific format, but just to throw a more specific exception, like "malformed iPhone PNG detected", I think it's Apple's responsability to write proper PNGs, not the responsability of others to read their malformed files.
Reacted by Brian Popow and AraHaan- changed the title
[-]Image.Load<Rgba32> Results in 'Bad compression method for ZLIB header: cmf=237' Exception[/-][+]Decoding malformed iPhone generated PNG throws 'Bad compression method for ZLIB header: cmf=237'[/+]on May 26, 2018 These files have been processed with an Apple-variation of pngcrush.
You can use PNGDecrush (source) to decrush the image, which can then be fed to other image libraries.
E.g.:
using (Stream input = File.OpenRead("34303888-73d65ca6-e705-11e7-88cf-6c16ad871172.png")) using (MemoryStream decrushed = new MemoryStream()) { PNGDecrusher.Decrush(input, decrushed); decrushed.Position = 0; var image = Image.Load(decrushed); }
Reacted by Vicente Penades, James Jackson-South, AraHaan and Saulius Menkevičius@qmfrederik Thanks for the input; that a really useful tool! 👍
I'm going to get around to natively handling this one day, need to do some cleanup of the decoder first though.
- added a commit that references this issue
on Apr 23, 2020
Prerequisites
DEBUGandRELEASEmodeDescription
Try loading the attached image and see that it generates a 'Bad compression method for ZLIB header: cmf=237' error. System.Drawing can open this image.
Steps to Reproduce
Image.Load(File.OpenRead("1.png"))
System Configuration
.NET Standard 2.0 Dll hosted in a .NET Framework 4.6.1 windows service