An efficient way to detect corrupted png files?

libpng, linux, png

Solution

A different possible solution would be to slightly change how your processor processes the files: Have it always create a file named temp.png (for example), and then rename it to the "correct" name once it's done. That way, you know if there is a file named temp.png around, then the process got interrupted, whereas if there is no such file, then everything is good.

(A variant naming scheme would be to do what Firefox's downloader does -- append .partial to the real filename to get the temporary name.)

Problem

I've written a program to process a bunch of png files that are generated by a seperate process. The capture mostly works, however there are times when the process dies and is restarting which leaves a corrupted image. I have no way to detect when the process dies or which file it dies one (there are ~3000 png files). Is there a good way to check for a corrupted png file?

Original source

Related problems