diff --git a/docs/agent-reports/audit.md b/docs/agent-reports/audit.md new file mode 100644 index 0000000..e5815ff --- /dev/null +++ b/docs/agent-reports/audit.md @@ -0,0 +1,69 @@ +# Audit (independent review) + +Branch `ap/audit`, on top of `c6e6e57` (play-integration merged). I read all of the Rust code (summit-core, summit-cli, +summit-gui), the README, `install.sh`, and the engine code on the paths Summit calls: `run.py`'s arguments, +`window_x11.py` (window pick, pid family, grab), and the SIGTERM handling. The rest of the Python engine (~18k lines: +capture, replay, looks, chiaki tap, ...) was **not** audited line by line. + +Severity: **High** = wrong behaviour in a normal use the README advertises; **Medium** = data loss, a crash on odd +input, or a wrong result in a plausible case; **Low** = edge case, hardening, or cosmetic. + +## Fixed (each with a test unless stated) + +| # | Severity | Finding | Fix | Test / check | +|---|---|---|---|---| +| 1 | High | `summit run --enhance`: when the engine ended first, Summit sent SIGTERM only to its direct child. A game started by a launch script (`run.sh` that does not `exec`) kept running, orphaned. | `engine::stop()` now finds the process's descendants in `/proc` before signalling, sends SIGTERM to all of them, and SIGKILLs what is left after the grace time. | `stop_also_stops_what_the_process_started`, `stop_kills_a_child_that_ignores_sigterm`, `descendants_parse_a_fake_proc`. **On the VM** with Voidrunner behind a non-exec script: the old binary left `top_down_shooter` running (re-parented to 1), the new one stopped it. | +| 2 | Medium | `summit run`: the display mode was applied before the game was spawned, but put back only on the success path. A command that could not be started (or an error while supervising) left the monitor in the game's mode. | A drop guard puts the old mode back on every way out of `run`. The error now names the command. | `on_drop_runs_on_early_return_too`. **On the VM**: `summit run -- /nonexistent/game` with a 1280x800@74.99 profile: the old binary left the screen at 1280x800, the new one went back to `1920x1080_120.00`. | +| 3 | Medium | Text VDF and binary VDF parsers recurse once per nesting level with no limit: a corrupt or crafted `localconfig.vdf`/`shortcuts.vdf` with deep nesting overflowed the stack (process abort, not an error). | Depth limit 64 (far above anything Steam writes); deeper is an `Err`. | `deep_nesting_is_an_error_not_a_stack_overflow` (both parsers, 200 000 levels), `odd_input_never_panics` (both). | +| 4 | Medium | Binary VDF read strings with `from_utf8_lossy`; `steam-add`/`steam-remove` then wrote the whole file back, so another shortcut with a non-UTF-8 name or path was silently rewritten with U+FFFD. | Non-UTF-8 string values are kept as raw bytes and written back byte-identical. | `non_utf8_strings_survive_a_round_trip`. | +| 5 | Medium | GUI: Play on Home's hero used `can_enhance` from whichever game's page was opened last, not the game being started. For example, a Lutris game with `enhance = true` could fail with "Enhance is not wired". | Enhance availability is computed for the entry being started. | No unit test (it needs a Slint window); it builds, and the page uses the same function. | +| 6 | Medium | `install.sh`: the engine was copied to `/usr/local/share/summit/engine` with sudo, then the venv was made there **without** sudo, which fails for any non-root user. | `chown` the engine folder to the installing user (non-root only) before the venv step. | `--dry-run` as user `nobody` prints the chown before the venv step. Not run for real (see below). | +| 7 | Low | `install.sh` built `sh -c "cd '$DIR' && ..."` strings: a `'` in `$SUMMIT_SRC_DIR`/`$SUMMIT_PREFIX` broke out of the quotes. | Commands take the paths as arguments (`cargo --manifest-path`, `uv venv `, `uv pip --python `). | `sh -n`, dry run. | +| 8 | Low | Engine argv: user values (file name, window title, profile `model`/`monitor`, `--out`, capture name) were separate argv items, so the engine's argparse read a value starting with `-` as an option. | `--opt=value` form; a relative file name starting with `-` gets `./`. | `user_values_cannot_become_engine_options`; the existing plan tests now expect the new form. On the VM the engine accepted `--window=pid:N` and found the game window. | +| 9 | Low | `scan::full` deduplicated heuristic finds by string prefix: a known `/games/Foo` hid `/games/FooBar`, and a known empty path (a Lutris YAML with `exe: ''`) hid **every** heuristic find. | Path-component comparison; empty known paths are ignored. | `dedupe_compares_whole_path_components`, `missing_and_odd_dirs_find_nothing` (missing dir, non-UTF-8 folder name). | +| 10 | Low | `summit add` / `summit art` stored non-UTF-8 paths lossily: the stored path named a file that does not exist, so the entry showed as not installed with no explanation. | Refused with a clear message (`state::path_text`); the same for `enhance --out`. | `non_utf8_paths_are_refused_not_mangled`. | +| 11 | Low | SteamGridDB art: the grid file's extension was whatever followed the last `.` of the URL (up to 4 chars, `/` allowed), so a URL could put text like `b/c` into the file name. It could not escape the grid folder, but the name was garbage. | Only `png`/`jpg`/`webp`/`ico`, default `png`. | `url_ext_only_yields_image_types`. | +| 12 | Low | Profiles and the Steam names cache were written in place (a crash mid-write left broken TOML/JSON). `state.json` and `ui.toml` used one fixed temp name, so the launcher and a `summit run` saving at the same moment could write into the same temp file. | One `write_atomic` with a per-process temp file for all four. | `write_atomic_replaces_and_leaves_no_temp`; `roundtrip_through_file` checks that no temp file is left. | +| 13 | Medium (docs) | README said `install.sh` had "a real build + install on this machine" and the `.deb` "builds and installs". The packaging report says only dry runs were done and the `.deb` was never installed. README also said the engine installer "is not built yet", which contradicts the installer row. | README rows now say dry-run only, and built but not installed. The signal-kill note now also says the display mode is not put back. | – | + +Checked and fine: profile ids cannot escape the profiles folder (every character except `[A-Za-z0-9_-]` becomes `_`). +Artwork ids are only map keys, never file names. Grid file names are numeric. The engine never goes through a shell +(no `shell=True`, every subprocess is an argv list). `summit run` passes the game command as argv. The engine already +treats SIGTERM as a clean quit. A damaged `state.json`/`ui.toml` loads as defaults. + +## Not fixed + +| Severity | Finding | Why not | +|---|---|---| +| Medium | Killing `summit run` itself (a signal to summit only, e.g. from a process manager) leaves the game and the engine running and the display mode changed. Ctrl+C in a terminal reaches all three (same process group), so that case is fine. | It needs signal handling in the CLI (a new dependency or `libc`), which is more than a fix. Documented in the README. | +| Low | `state.json` has no lock: if the launcher saves a pin while `summit run` saves a session, the later write wins and the other change is lost (each write is now whole, see #12). | Needs file locking. Rare: the GUI reloads the file just before every save. | +| Low | `stop()` collects descendant PIDs and may signal them up to the grace time later; a PID reused within that time could get the signal. | Inherent in PID-based kill without pidfds or cgroups. The window is a few seconds. | +| Low | `steam-add` writes `LaunchOptions` as `run -- enhance ` without quoting: a summit path or a `ui.toml` target with spaces breaks. | How Steam splits LaunchOptions for non-Steam shortcuts could not be checked (no Steam here), so a quoting change could not be tested. | +| Low | Profile file names: ids that differ only in punctuation or non-ASCII characters (`custom:café` / `custom:cafè`) share one profile file. | Changing the file naming would orphan existing profiles. | +| Low | Binary VDF keys (not values) are still read lossily. | Steam's keys are ASCII in practice. | +| Low | KDE Wayland: a monitor name containing `.` would break the `kscreen-doctor output....` argument. | Untestable without KDE Wayland; real output names have no dots. | +| Low | Controller: a `/dev/input/js*` that exists but cannot be opened (permissions) gets a new reader thread every 2 s, each of which fails at once. | Harmless apart from the churn; not tested with a real device. | +| Low | `supervise()` returns early on a `try_wait` error and leaves both processes running. | Should not happen in practice. | +| – | `cargo clippy --workspace --all-targets`: 9 warnings remain, all style (`map_or` → `is_some_and`, a `== false` in a test, a complex type, a large `Err` from `ureq`). None points at a bug, so I left them. | Style only. | +| – | Most of the Python engine was not audited. Its tests were not run here (no numpy/pytest on this host); I changed no Python. | Size and scope. | + +## What I verified and how + +- `cargo test --workspace` before every commit. Final run: 1 (cli) + 86 (core) + 17 (gui) tests pass. Before the audit: 72 + 17. +- On the GPU VM (KDE neon X11), with a release `summit` built from this branch in `/home/user/summit-audit` (built + before the last code commit, which only changes an error message), and the old one from `/home/user/summit-live` + for comparison: + - `summit run custom:voidrunner --enhance -- vr.sh` (`vr.sh` starts `top_down_shooter` without `exec`), then SIGTERM + to the engine's PID. New binary: the engine ran on the game (I looked at the screenshot: RIFE stats over + Voidrunner's menu), it was started with `--window=pid:N`, and after the SIGTERM both `vr.sh` and + `top_down_shooter` were gone. Old binary: `top_down_shooter` was still running with parent 1 (I then stopped it by PID). + - A profile with a 1280x800@74.99 mode and a command that does not exist: the new binary put `1920x1080_120.00` back; + the old one left the screen at 1280x800. The test profile was deleted and the mode restored afterwards. +- `install.sh --dry-run --yes` as user `nobody`: the chown comes before the venv commands, and no `sh -c` wraps a path. +- Not verified: `install.sh` for real, the GUI change in a window, anything that needs Steam or Wayland. + +## Environment note + +The host's root disk was 100% full at the start, so nothing would build. With the owner's OK I deleted the `target/` +folders of the merged worktrees `summit-wt-play-integration`, `summit-wt-packaging` and `summit-wt-steam-shortcuts`. +They are build output and can be rebuilt.