sketch-image-compressor icon indicating copy to clipboard operation
sketch-image-compressor copied to clipboard

"Export All Assets" can swap files due to pngcrush shared tempfile

Open iccir opened this issue 8 years ago • 3 comments

pngcrush uses a temp file (I believe pngout.png) when running. When "Export All Assets" is used, multiple NSTask's are created, all of which use pngcrush. One pngcrush can write to the temp file and then another pngcrush reads from it.

Steps to reproduce:

  1. Remove advpng and optipng from compress-full-png.sh. This ensures that pngcrush will always override the file rather than bailing.
  2. Export All Assets

The following document:

screen shot 2017-07-07 at 9 15 22 pm

Produces these results:

screen shot 2017-07-07 at 9 15 28 pm

iccir avatar Jul 08 '17 04:07 iccir

Note: this won't show up usually since advpng or optipng will probably produce a smaller file than pngcrush would produce. The failure case occurs when pngcrush produces the smaller file.

iccir avatar Jul 08 '17 04:07 iccir

From the pngcrush changelog:

Added "-ow" (overwrite) option. The input file is overwritten and the output file is just used temporarily and removed after it is copied over the input file.. If you do not specify an output file, "pngout.png" is used as the temporary file. Caution: the temporary file must be on the same filesystem as the input file. Contributed by a group of students of the University of Paris who were taking the "Understanding of Programs" course and wished to gain familiarity with an open-source program.

It looks like the fix is adding a tempfile name after the input file name:

"$basedir"/pngcrush -ow -reduce -blacken -bail -rem alla -new "$1" "$1".tmp

iccir avatar Jul 09 '17 01:07 iccir

I saw a similar issue just today, after an Export All, one of my exported png images was the wrong size (seemed to be a file from another size).

pcolton avatar Apr 02 '19 10:04 pcolton