Hi. When using the -ow option to overwrite the source file with the modified file, pngcrush creates a temporary file named "pngout.png" in the current working directory. If the file already exists, it overwrites it. This is not documented, and could cause data loss. It could even be considered a security concern. Also, it causes pngcrush to fail if the output is not in the same filesystem as the current directory. Regards,
I am also surprised that a fixed file name is used. Why not calling, in pseudocode, something in the vein of mkstemp(if $TMPDIR exists then $TMPDIR+"/pngoutXXXXXX.png" else "/tmp/pngoutXXXXXX.png") or simply mkstemp("pngoutXXXXXX.png")? It seems to me that mkstemp(…) and its sister functions have more merits than a constant filename.
Upon thinking more, having the temporary file on the same partition as the original file ensures that if the computer crashes, the directory entry for the original file will more likely point to valid data. So the logic should probably be as follows: template="pngoutXXXXXX.png.tmp"; if directory_of_the_original_file is writable and has enough space then use directory_of_the_original_file + template as a temporary file else if $TMPDIR exists, is on the same partition as the original file, is writable, and has enough space then use $TMPDIR + "/"+ template as a temporary file else if "/tmp" exists, is on the same partition as the original, is writable, and has enough space then use "/tmp/" + template as a temporary file else if "/var/tmp" exists, is on the same partition as the original, is writable, and has enough space then use "/var/tmp/" + template as a temporary file else overwrite the original file directly
In particular, notice that I suggested the extension .tmp (or the double extension .png.tmp). This way, if the computer crashes after pngcrush created this file but not yet cleaned it up, so this file will be left over, the end user or various cleanup programs would know that this file is temporary and can be manually or semi-automatically deleted (in the vein of `find ~ -iname \*.tmp`, followed by `find ~ -iname \*.tmp -delete`).