Skip to content

fix: --upscale 0 panic, give a clean error instead - #7

Open
bluzername wants to merge 1 commit into
heydeer:mainfrom
bluzername:fix-upscale-zero-panic
Open

bluzername wants to merge 1 commit into
heydeer:mainfrom
bluzername:fix-upscale-zero-panic

Conversation

@bluzername

Copy link
Copy Markdown

`slimdeer file -o out.png --upscale 0` was crashing: `Vec::chunks_exact` need a chunk size that is not zero, and `upscale()` in `cli/tools.rs` build the output width as `image.width * k`, so k=0 give width 0 and `encode_rgba` panic on `pixels.chunks_exact(0)`. Every other bad option (like `--target 101`) fail with a normal usage error, not a panic, so this one should too.

What change:

  • `cli/args.rs`: `--upscale 0` is now checked the same place as the other `--upscale` check (`--upscale needs -o`), and give `--upscale: at least 1, not 0`, exit 2.
  • `tests/cli.rs`: added `["a.png", "-o", "x.png", "--upscale", "0"]` to the existing `a_command_it_cant_run_exits_2` test, so it is checked the same way as the other usage error.

`--upscale` is a helper for `bench/bench.py`, not in `--help`, but a wrong value there still should not panic the program.

I could not run `cargo test` myself here (no code execution in my environment this run), so please double check the test pass on your side. Happy to adjust if I get something wrong.

slimdeer file -o out.png --upscale 0 was crashing (Vec::chunks_exact
need a chunk size that is not zero), not failing nice like the other
bad option do. --upscale is a helper for bench/bench.py (K times
enlarge), but a typo like 0 still should not panic the program.

Now --upscale 0 is checked with the other --upscale checks and give a
normal usage error, exit 2, same place as --target 101 or other bad
value. Added to the same test that already cover these usage error.
@vercel

vercel Bot commented Nov 15, 2026

Copy link
Copy Markdown

@bluzername is attempting to deploy a commit to the Adastralab AI Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant