JamieMason / JamieMason/ImageOptim-CLI

fix(pngquant): handle malformed png file errors

Open
#185 0 comments 0 reactions 0 assignees View on GitHub
Status: In Progress Type: Fix
Dominant language
Rust
Stars
3.5k
Forks
128
PR merge metrics
No merged PRs in 30d

Description

## Steps To Reproduce The Error

```sh
❯ 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

- macOS: 10.15.7
- /Applications/ImageOptim.app: 1.8.8 (brew)
- /Applications/ImageAlpha.app: 1.5.1 (brew)
- /Applications/JPEGmini.app: 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?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the test at src/is-supported.ts#L4 and reproduce the malformed file case using the commands in the issue. Check how the CLI handles the pngquant failure, then verify that malformed PNG files are ignored or reported instead of crashing.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, rust, typescript
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.