How to Diagnose and Repair a Corrupted PNG File

November 08, 2026 · PNG.now Editorial · PNG Essentials

Separate storage failure, structural damage and unsupported PNG features before attempting repair.

Classify the Failure Before Acting

A PNG that refuses to open is not a single problem. The W3C PNG specification (ISO/IEC 15948, third edition) defines a strict byte-level format, and failure falls into three distinct categories. Identify which applies before you touch a repair tool.

Storage failure. Bits flipped or sectors lost during transfer, disk aging, or truncation. The file retains valid structure but carries incorrect data inside chunks. CRCs fail, decompressors choke, or pixel values shift.

Structural damage. Missing or malformed critical chunks (IHDR, IDAT, IEND), broken CRC values, or invalid chunk ordering. The file violates the PNG stream format and cannot be parsed.

Unsupported feature. The file is technically valid but uses features your viewer cannot decode—16-bit grayscale with alpha, sBIT on certain color types, or proprietary ancillary chunks. The file is not corrupted; your tool is inadequate.

Only storage failure and structural damage are repairable. Unsupported features require a different viewer or a format converter, not a repair tool.


Verify the 8-Byte Signature

Every valid PNG begins with an 8-byte signature: decimal 137 80 78 71 13 10 26 10. If this signature is missing or altered, the file is not a PNG or has been truncated before the first byte of the IHDR chunk.

head -c 8 corrupt.png | xxd -p
# Expected: 89504e470d0a1a0a

If the output differs, the file is beyond repair as a PNG. You may recover raw pixel data if you know the exact dimensions and bit depth, but the file will never open in a standard viewer.


Validate the IHDR Chunk

The IHDR chunk must be the first chunk after the signature. Per §4.1.1 of the specification, its data field is always 13 bytes: width (4 bytes), height (4 bytes), bit depth (1 byte), color type (1 byte), compression method (1 byte), filter method (1 byte), and interlace method (1 byte).

Run pngcheck to parse the chunk:

pngcheck -v corrupt.png

CRC mismatch. The chunk CRC does not match its data. If the 13-byte data field is intact, this is repairable. Force CRC recomputation:

pngcrush -rem all -fix corrupt.png fixed.png

Impossible values. Width or height of 0. Bit depth not in {1,2,4,8,16}. Color type greater than 6. Compression method not 0. Filter method not 0. Interlace method not in {0,1}. These indicate bit-level storage failure inside the IHDR data itself. Without a known-good copy of the header, the file is unrecoverable.

Missing IHDR. pngcheck reports "chunk order violation" or "no IHDR." You cannot reconstruct the image geometry from pixel data alone. This is terminal.


Inspect the IDAT Stream

IDAT chunks contain the compressed, filtered image data. The specification (§4.2.1) requires all IDAT chunks to be concatenated in file order and decompressed as a single zlib data stream.

Observable diagnostics

pngcheck -v corrupt.png | grep "IDAT"

"zlib: inflate error" or "incorrect data check." The compressed stream is internally inconsistent. This is the most common repairable failure and usually indicates storage-level bit errors.

"too many IDAT chunks." The specification imposes no hard limit on chunk count, but some decoders enforce a maximum. If pngcheck reports this, the file may be structurally valid but rejected by a strict viewer.

"unexpected end of IDAT." The file was truncated mid-stream. Some decompressed data exists, but the image is incomplete.

Repair approaches

Single corrupt IDAT chunk with a known-good reference. Locate the corrupted byte range by comparing zlib streams from the damaged and reference files. Replace the damaged bytes manually in a hex editor. This is not automatable.

Truncated IDAT with intact IHDR. Calculate the expected uncompressed size from width, height, bit depth, and color type. Pad the truncated stream with zero bytes and attempt decompression. The pngfix tool from libpng can attempt this:

pngfix --strict corrupt.png fixed.png

Expect visual artifacts where data is missing. The image will open, but content below the truncation point will be gray or patterned noise.

Multiple IDAT chunks with ordering errors. Reorder chunks by file offset. pngfix attempts this automatically when chunk sequence is recoverable.


Strip Ancillary Chunks to Isolate Viewer Rejection

A structurally valid PNG can still fail to open if a viewer cannot process an ancillary chunk. The specification defines several that cause problems in practice:

  • sBIT (significant bits). The W3C PNG 3.0 draft notes this chunk is "often misapplied" and can cause decoders to misinterpret bit depth.
  • cHRM (chromaticity) and iCCP (embedded ICC profile). Mismatched or malformed profiles produce color shifts or outright rejection by strict parsers.
  • tEXt, zTXt, iTXt (text metadata). Oversized chunks can trigger buffer overflows in older viewers.

Strip all ancillary chunks and test:

pngcrush -rem all -noreduce corrupt.png stripped.png

If stripped.png opens correctly, the original file was structurally valid. The problem is an ancillary chunk your viewer rejects. Re-add critical metadata selectively with exiftool or pngmeta.


Verify the IEND Chunk

The IEND chunk must be the final chunk in the file. Its data field is always 0 bytes. The fixed 12-byte sequence for an IEND chunk is 00 00 00 00 49 45 4E 44 AE 42 60 82.

Missing IEND. Many viewers tolerate this if the IDAT stream is complete, but the file is technically invalid. Append the 12-byte sequence above with a hex editor.

Data after IEND. Trailing garbage is common after HTTP downloads that include extra bytes. Strip it:

pngcrush -rem all -fix trailing.png output.png

Hard Limits on Recovery

Some corruption is not repairable under any circumstances.

  1. Missing or corrupt IHDR with no backup. Width, height, bit depth, and color type cannot be reconstructed from pixel data alone. The file is a loss.
  2. IDAT stream with more than approximately 5% random bit errors. The zlib decompressor will fail catastrophically. No tool can recover the original image.
  3. Zero-length file or signature-only file. No image data exists.
  4. Deliberate destruction (overwritten with zeros, random bytes, or encrypted without a key). No recovery is possible.

For any of these, the only option is a backup or a different source file.


Validate After Repair

After any repair attempt, confirm the result:

pngcheck -v fixed.png

The output must end with "OK" and no errors. A file that passes pngcheck can still contain visual artifacts if the IDAT stream was padded or recompressed incorrectly. Compare against a known-good reference using a perceptual hash if one is available.

Reference: W3C PNG Specification, Third Edition. https://www.w3.org/TR/png-3/