JamieMason / ImageOptim-CLI

Make optimisation of images part of your automated build process
https://foldleft.io/image-tools
MIT License
3.45k stars 125 forks source link

crash on malformed png files #185

Open Fil opened 3 years ago

Fil commented 3 years ago

Steps To Reproduce The Error

❯ echo "hello" > file.png
❯ imageoptim --imagealpha  file.png
i Running ImageAlpha...
! Command failed with exit code 2 (ENOENT): /Applications/ImageAlpha.app/Contents/MacOS/pngquant --ext=.png --force --skip-if-larger --speed=1 --quality=65-80 256 -- /var/folders/57/f83bftsx79b9ylc2gzbdmdfw0000gp/T/imageoptim-cli/file.png

! Please raise an issue at https://github.com/JamieMason/ImageOptim-CLI/issues

    Error: Command failed with exit code 2 (ENOENT): /Applications/ImageAlpha.app/Contents/MacOS/pngquant --ext=.png --force --skip-if-larger --speed=1 --quality=65-80 256 -- /var/folders/57/f83bftsx79b9ylc2gzbdmdfw0000gp/T/imageoptim-cli/file.png
        at makeError (/usr/local/Cellar/imageoptim-cli/3.0.2/libexec/lib/node_modules/imageoptim-cli/dist/imageoptim:6571:11)
        at handlePromise (/usr/local/Cellar/imageoptim-cli/3.0.2/libexec/lib/node_modules/imageoptim-cli/dist/imageoptim:6368:26)
        at process._tickCallback (internal/process/next_tick.js:68:7)

Expected Behaviour

ignore or report malformed png files

Actual Behaviour

crash

Version Numbers or N/A

Help Needed

would the test at https://github.com/JamieMason/ImageOptim-CLI/blob/e65bb4a24c23975297aac716cf77fc4b87827ef9/src/is-supported.ts#L4 be complemented by a magic number test on the actual file's contents?