Skip to content

engine: refuse negative indices instead of targeting element 0 - #1793

Merged
echelon merged 1 commit into
storytold:mainfrom
midasmatterhorn:fix/engine-negative-index
Oct 15, 2026
Merged

echelon merged 1 commit into
storytold:mainfrom
midasmatterhorn:fix/engine-negative-index

Conversation

@midasmatterhorn

Copy link
Copy Markdown
Contributor

version.delete, version.restore, version.rename/version.update, pointColor.delete and redeye.catchlight/redeye.delete parse index with f64_req(..)? as usize; Rust's float-to-int cast saturates, so index: -1 becomes 0 and the i >= len checks never see a negative. A caller over the control channel, MCP or CLI sending index: -1 silently deleted, restored or renamed version 0 (or the first point-colour sample / red-eye correction) and got ok back.

history.restore already guards with is_finite() && i >= 0.0 and spot_index uses as_u64; a new index_req helper applies the same guard to the five sites, with behaviour for valid indices unchanged. Regression test negative_indices_are_refused creates a version and asserts the three version.* commands with index: -1 return an error and version 0 is untouched — before the fix the first call deletes it.

Partially addresses #1740 (finding 4, negative index). Targeted tests green locally; cargo xtask ci left to the project runners.

`version.*`, `pointColor.delete` and `redeye.catchlight`/`redeye.delete`
parsed `index` with `f64_req(..)? as usize`. Rust's float-to-int cast
saturates, so `index: -1` became 0 and the bounds checks never saw a
negative: a caller sending `index: -1` silently deleted, restored or
renamed version 0 (or the first point-colour sample / red-eye correction)
and got `ok` back. `history.restore` already guards this and `spot_index`
uses `as_u64`.

New `index_req` helper in `cmd/mod.rs` (the same finite, non-negative
guard) is used by the five sites. Behaviour for valid indices is
unchanged.

Regression test `negative_indices_are_refused` creates a version, then
asserts `version.delete/restore/rename` with `index: -1` error and version
0 is untouched (before the fix the first one deletes it).
@echelon

echelon commented Oct 15, 2026

Copy link
Copy Markdown
Member

Thank you @midasmatterhorn! This landed on main in integration batch 36 (#1843).

If you haven't already, please join our Discord: https://discord.gg/artcraft. We'd love to have you there.

@midasmatterhorn

Copy link
Copy Markdown
Contributor Author

Appreciate 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.

2 participants