test(host): the control bridge's memory bound is run on a region's edges #3010

Merged
HumanBean merged 1 commit from PedroRossi/Longshot:test/hos-mem-region-bounds into main 2026-12-05 19:04:30 +00:00
Contributor

Summary

Nothing fails if the control bridge's memory bound breaks. With HOS_CONTROL_MEM on, the control bridge (the
local socket tools drive the game through) reads and writes the game's memory for its client, and hos_mem_region
(host/hos_mem.c) is the one check that keeps those ranges inside it: a range it wrongly accepts reaches memory
outside the guest. No test runs it: tests/control_test.c links fake_mem_region in its place, and none of the tests
that build the real hos_mem.c notices it broken. On main @ 1938a302, with its region end check or its empty-range check
taken out, each of them gives the same result as before.

This adds checks to tests/test_host_free_marks.py, which already builds the real hos_mem.c: on the lower of two
regions (so the end of the window doesn't catch a range for it), a range across the region's end, an empty range, one
that wraps past 2^64, and one in the region once it is freed. They fail with either check removed. A test only.

Testing

Tested: on this PC (Linux): the new checks pass, and fail with the end check removed and with the
empty-range check removed. On main, those two removals change no test's result (test_host_free_marks.py,
test_host_guest_writes.py, test_libc_hooks.py and test_vk_collect_window.py pass either way; test_vcore_region_free.py
fails either way, as on main). mise run test (--strict) on main @ 1938a302, and on main with this change merged (together with #3009, #3011, #3012, #3013, #3014, from the same audit): 775 passed, 145 failed, 10 skipped both ways, so none fails only with it. The 145 are named at the end.

Still to test:
None: a test, run here.

Measurements

Nothing to measure: a test; the game's code doesn't change.

Risks

None: a test.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named).
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.
The 145 checks of mise run test that fail on main @ 1938a302 on this PC too, with or without this change

97 need a tool this PC doesn't have on PATH (--strict fails them):

  • clang (63): test_audio_output_devices.py, test_box_light_reuse.py, test_camera_centering.py, test_camera_speed.py, test_drive_target.py, test_dynres_sites.py, test_exclusive_marks.py, test_fixed_scale_sites.py, test_floor_carry_step.py, test_frame_rate_cap_step.py, test_frame_whole.py, test_free_view_anchor.py, test_fullscreen_monitor_platform.py, test_high_fps_fixes.py, test_horse_jump_step.py, test_hos_ab.py, test_hud_layout.py, test_jump_takeoff_step.py, test_linux_audio_output.py, test_loop_step.py, test_menu_hooks.py, test_microphone_test_gain.py, test_monitor_friendly_names.py, test_mouse_native.py, test_movement_speed.py, test_movie_frame_count.py, test_nvn_null_pool.py, test_nvn_tex_builder_guard.py, test_ocarina_wait.py, test_ocb_hold.py, test_oot_barrier.py, test_oot_camera_clearance.py, test_oot_cloth.py, test_oot_cloth_60.py, test_oot_cloth_time.py, test_oot_damage.py, test_oot_fov.py, test_oot_heap_retry.py, test_oot_jitter.py, test_oot_shadow.py, test_oot_shadow_fit.py, test_oot_transition_autosave.py, test_oot_voice_option.py, test_oot_wide_bubble.py, test_oot_wide_save_picture.py, test_player_update_sites.py, test_sampler_stack_walk.py, test_saved_turn_rate.py, test_scarecrow_timing.py, test_scene_format.py, test_sdl_monitor_names.py, test_shadow_slot.py, test_song_note_cue.py, test_sound_held_frames.py, test_sprint.py, test_svc_core_mask.py, test_tex_compact.py, test_text_speed.py, test_title_card_sites.py, test_water_substeps.py, test_web_floor_steps.py, test_wide_sites.py, test_wide_ui.py
  • spirv-val (20): f2i_immediate, global_load_16, native_suatom, test_coop_spirv.py, test_default_point_size.py, test_depth_sample_types.py, test_draw_parameters.py, test_fsr4_tune.py, test_guest_page_fast32.py, test_image_arrays.py, test_mesh_fallback_layout.py, test_mesh_unreachable_outputs.py, test_mma_software.py, test_native_float_atomic_add.py, test_nonuniform_image_arrays.py, test_spirv_struct_identity.py, test_texture_phi_dominance.py, test_unsigned_image_types.py, test_vendor_translation.py, test_wmma16_spirv_val.py
  • clang++ (7): test_dead_targets_sweep.py, test_lower_depbar.py, test_lower_lds_after_sts.py, test_lower_register_markers.py, test_native_suatom.py, test_program_answer_domains.py, test_target_pool_cap.py
  • glslang (5): test_framegen_hdr.py, test_fsr3fi_hud_layer.py, test_fsr3fi_hudless_colour.py, test_host_shaders.py, test_temporal_present_bandwidth.py
  • glslang, spirv-val (1): test_fsr3_shaders.py
  • llvm-mc (1): test_lifter.py

48 fail on main itself: test_blocks_at_start.py, test_bug_report.py, test_cloth_kernels.py, test_cloth_loops.py, test_cloth_sphere.py, test_cloth_step12.py, test_cloth_step8.py, test_cloth_step9.py, test_control_picture.py, test_crash_record.py, test_crt_options.py, test_dev_update.py, test_dlssg_pace.py, test_draw_stream_visibility.py, test_framegen_resources.py, test_fsr_uniform_ownership.py, test_game_boundary.py, test_guest_holes.py, test_image_reaper_threads.py, test_image_view_retry.py, test_input_background.py, test_keyboard_option.py, test_linux_pressure.py, test_loaded_modules_drop.py, test_log_levels.py, test_menu_keys.py, test_menu_save_atomic.py, test_mesh_first_types.py, test_oot_occ_raster.py, test_option_ids.py, test_perf_send.py, test_pipeline_tour.py, test_present_acquire_ahead.py, test_present_image_free.py, test_present_source_crop.py, test_program_cache_cleanup.py, test_program_cache_one_variant.py, test_readback_timeout_reuse.py, test_recording_admission.py, test_screensaver.py, test_switch_table.py, test_target_retention.py, test_tex_desc_memo.py, test_thinlto_tls.py, test_upscaler_round_trip.py, test_vram_compact.py, test_windows_display_startup.py, test_windows_on_linux.py


Found in an AI-assisted audit of the repository. The test, the fix, the runs and this description were made with Claude Code; I reviewed them.

Co-Authored-By: Claude Opus 5.5 [email protected]

🤖 Generated with Claude Code

## Summary Nothing fails if the control bridge's memory bound breaks. With `HOS_CONTROL_MEM` on, the control bridge (the local socket tools drive the game through) reads and writes the game's memory for its client, and `hos_mem_region` (`host/hos_mem.c`) is the one check that keeps those ranges inside it: a range it wrongly accepts reaches memory outside the guest. No test runs it: `tests/control_test.c` links `fake_mem_region` in its place, and none of the tests that build the real `hos_mem.c` notices it broken. On main @ 1938a302, with its region end check or its empty-range check taken out, each of them gives the same result as before. This adds checks to `tests/test_host_free_marks.py`, which already builds the real `hos_mem.c`: on the lower of two regions (so the end of the window doesn't catch a range for it), a range across the region's end, an empty range, one that wraps past 2^64, and one in the region once it is freed. They fail with either check removed. A test only. ## Testing **Tested:** on this PC (Linux): the new checks pass, and fail with the end check removed and with the empty-range check removed. On main, those two removals change no test's result (test_host_free_marks.py, test_host_guest_writes.py, test_libc_hooks.py and test_vk_collect_window.py pass either way; test_vcore_region_free.py fails either way, as on main). `mise run test` (`--strict`) on main @ 1938a302, and on main with this change merged (together with #3009, #3011, #3012, #3013, #3014, from the same audit): 775 passed, 145 failed, 10 skipped both ways, so none fails only with it. The 145 are named at the end. **Still to test:** None: a test, run here. ## Measurements Nothing to measure: a test; the game's code doesn't change. ## Risks None: a test. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [x] `mise run test` passes (any failure that also fails on `main` is named). - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. <details><summary>The 145 checks of <code>mise run test</code> that fail on main @ 1938a302 on this PC too, with or without this change</summary> 97 need a tool this PC doesn't have on PATH (`--strict` fails them): - clang (63): test_audio_output_devices.py, test_box_light_reuse.py, test_camera_centering.py, test_camera_speed.py, test_drive_target.py, test_dynres_sites.py, test_exclusive_marks.py, test_fixed_scale_sites.py, test_floor_carry_step.py, test_frame_rate_cap_step.py, test_frame_whole.py, test_free_view_anchor.py, test_fullscreen_monitor_platform.py, test_high_fps_fixes.py, test_horse_jump_step.py, test_hos_ab.py, test_hud_layout.py, test_jump_takeoff_step.py, test_linux_audio_output.py, test_loop_step.py, test_menu_hooks.py, test_microphone_test_gain.py, test_monitor_friendly_names.py, test_mouse_native.py, test_movement_speed.py, test_movie_frame_count.py, test_nvn_null_pool.py, test_nvn_tex_builder_guard.py, test_ocarina_wait.py, test_ocb_hold.py, test_oot_barrier.py, test_oot_camera_clearance.py, test_oot_cloth.py, test_oot_cloth_60.py, test_oot_cloth_time.py, test_oot_damage.py, test_oot_fov.py, test_oot_heap_retry.py, test_oot_jitter.py, test_oot_shadow.py, test_oot_shadow_fit.py, test_oot_transition_autosave.py, test_oot_voice_option.py, test_oot_wide_bubble.py, test_oot_wide_save_picture.py, test_player_update_sites.py, test_sampler_stack_walk.py, test_saved_turn_rate.py, test_scarecrow_timing.py, test_scene_format.py, test_sdl_monitor_names.py, test_shadow_slot.py, test_song_note_cue.py, test_sound_held_frames.py, test_sprint.py, test_svc_core_mask.py, test_tex_compact.py, test_text_speed.py, test_title_card_sites.py, test_water_substeps.py, test_web_floor_steps.py, test_wide_sites.py, test_wide_ui.py - spirv-val (20): f2i_immediate, global_load_16, native_suatom, test_coop_spirv.py, test_default_point_size.py, test_depth_sample_types.py, test_draw_parameters.py, test_fsr4_tune.py, test_guest_page_fast32.py, test_image_arrays.py, test_mesh_fallback_layout.py, test_mesh_unreachable_outputs.py, test_mma_software.py, test_native_float_atomic_add.py, test_nonuniform_image_arrays.py, test_spirv_struct_identity.py, test_texture_phi_dominance.py, test_unsigned_image_types.py, test_vendor_translation.py, test_wmma16_spirv_val.py - clang++ (7): test_dead_targets_sweep.py, test_lower_depbar.py, test_lower_lds_after_sts.py, test_lower_register_markers.py, test_native_suatom.py, test_program_answer_domains.py, test_target_pool_cap.py - glslang (5): test_framegen_hdr.py, test_fsr3fi_hud_layer.py, test_fsr3fi_hudless_colour.py, test_host_shaders.py, test_temporal_present_bandwidth.py - glslang, spirv-val (1): test_fsr3_shaders.py - llvm-mc (1): test_lifter.py 48 fail on main itself: test_blocks_at_start.py, test_bug_report.py, test_cloth_kernels.py, test_cloth_loops.py, test_cloth_sphere.py, test_cloth_step12.py, test_cloth_step8.py, test_cloth_step9.py, test_control_picture.py, test_crash_record.py, test_crt_options.py, test_dev_update.py, test_dlssg_pace.py, test_draw_stream_visibility.py, test_framegen_resources.py, test_fsr_uniform_ownership.py, test_game_boundary.py, test_guest_holes.py, test_image_reaper_threads.py, test_image_view_retry.py, test_input_background.py, test_keyboard_option.py, test_linux_pressure.py, test_loaded_modules_drop.py, test_log_levels.py, test_menu_keys.py, test_menu_save_atomic.py, test_mesh_first_types.py, test_oot_occ_raster.py, test_option_ids.py, test_perf_send.py, test_pipeline_tour.py, test_present_acquire_ahead.py, test_present_image_free.py, test_present_source_crop.py, test_program_cache_cleanup.py, test_program_cache_one_variant.py, test_readback_timeout_reuse.py, test_recording_admission.py, test_screensaver.py, test_switch_table.py, test_target_retention.py, test_tex_desc_memo.py, test_thinlto_tls.py, test_upscaler_round_trip.py, test_vram_compact.py, test_windows_display_startup.py, test_windows_on_linux.py </details> --- Found in an AI-assisted audit of the repository. The test, the fix, the runs and this description were made with Claude Code; I reviewed them. Co-Authored-By: Claude Opus 5.5 <[email protected]> 🤖 Generated with [Claude Code](https://claude.com/claude-code)
test(host): the control bridge's memory bound is run on a region's edges
Some checks are pending
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Blocked by required conditions
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Blocked by required conditions
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Blocked by required conditions
CI / What the change needs (pull_request) Blocked by required conditions
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Blocked by required conditions
CI / Third-party parts and guide screenshots (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
PR description / Title and description (pull_request_target) Successful in 8s
1064bba4c2
hos_mem_region (host/hos_mem.c) is all that keeps the control bridge's memory reads and writes inside the game's
memory, and no test ran it: control_test.c and the others link stand-ins. tests/test_host_free_marks.py, which builds
the real hos_mem.c, now asks it about the lower of two regions: a range across its end, an empty one, one that wraps
past 2^64, one in a freed region. It fails with the end check or the empty-range check removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
PedroRossi changed title from WIP: test(host): the control bridge's memory bound is run on a region's edges to test(host): the control bridge's memory bound is run on a region's edges 2026-12-02 16:12:13 +00:00
Owner
@review
BeanBot left a comment

Recommendation: Approve. The new assertions cover the stated region-end and empty-range cases, and the author reports that each catches its corresponding removed check. CI is still running, and the test inherits a compiler selection that can skip the new coverage on supported setups. Nothing blocking is left. Recommend approval; not approved on the forge.

Adds game-free checks for address-region boundaries, empty and wrapping ranges, and freed regions. It improves regression coverage without changing player code, but ties that coverage to a test harness that hard-codes GCC.

Should fix (1): not blocking, but worth doing before merging.

  • L1 tests/test_host_free_marks.py:218: The new checks inherit a harness that hard-codes GCC instead of honoring the selected C compiler. (more on the line) Do: Use the test runner's {cc} compiler selection and honor CC for direct invocation, while retaining an explicit --cc override.

@fix can do L1.

Checks: Still running: 10 checks.

More: does it help, other systems, switches, what was read

Does it help: Yes: the author reports that the new checks pass and fail when either the region-end check or the empty-range check is removed. This is not a performance change.

Other systems: The changed assertions run only in a test fixture; they do not change the game, renderer, saves, input, audio, or build. The fixture has Windows-specific paths, but the reported run was on Linux and its runner requires GCC.

Switches: None added, changed, or removed.

Reviewed: 1064bba4c2 against 1938a302fe: Read AGENTS.md, CONTRIBUTING.md, the pull request template, docs/dev/standards.md, the full changed test, host/hos_mem.c, its guest-range helper, and the control bridge's memory-service callers. Read the full diff and commit; skimmed test-runner compiler selection and CI workflow references. docs/review-checklist.md and the adjacent Tooling checkout were absent. No recorded runs or generated files were changed.; nothing run (a code review).

Checked and fine:

  • The lower of two allocated regions puts the crossing-range check inside the fixture's guest window.
  • The empty-range assertion reaches the real hos_mem_region implementation.
  • The commit records AI assistance and the diff contains no game-derived output, generated files, API changes, or switch changes.

Testing: No commands from the project, builds, or tests were run, as requested. The author's Linux results are reported in the pull request; CI remains in progress.

Overlaps and merge order: Not checked; network access was unavailable.


Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

**Recommendation: Approve.** The new assertions cover the stated region-end and empty-range cases, and the author reports that each catches its corresponding removed check. CI is still running, and the test inherits a compiler selection that can skip the new coverage on supported setups. Nothing blocking is left. Recommend approval; not approved on the forge. Adds game-free checks for address-region boundaries, empty and wrapping ranges, and freed regions. It improves regression coverage without changing player code, but ties that coverage to a test harness that hard-codes GCC. **Should fix (1)**: not blocking, but worth doing before merging. - **L1** `tests/test_host_free_marks.py:218`: The new checks inherit a harness that hard-codes GCC instead of honoring the selected C compiler. (more on the line) **Do:** Use the test runner's {cc} compiler selection and honor CC for direct invocation, while retaining an explicit --cc override. `@fix` can do L1. **Checks:** Still running: 10 checks. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Yes: the author reports that the new checks pass and fail when either the region-end check or the empty-range check is removed. This is not a performance change. **Other systems:** The changed assertions run only in a test fixture; they do not change the game, renderer, saves, input, audio, or build. The fixture has Windows-specific paths, but the reported run was on Linux and its runner requires GCC. **Switches:** None added, changed, or removed. **Reviewed:** 1064bba4c248 against 1938a302feb0: Read AGENTS.md, CONTRIBUTING.md, the pull request template, docs/dev/standards.md, the full changed test, host/hos_mem.c, its guest-range helper, and the control bridge's memory-service callers. Read the full diff and commit; skimmed test-runner compiler selection and CI workflow references. docs/review-checklist.md and the adjacent Tooling checkout were absent. No recorded runs or generated files were changed.; nothing run (a code review). **Checked and fine:** - The lower of two allocated regions puts the crossing-range check inside the fixture's guest window. - The empty-range assertion reaches the real hos_mem_region implementation. - The commit records AI assistance and the diff contains no game-derived output, generated files, API changes, or switch changes. **Testing:** No commands from the project, builds, or tests were run, as requested. The author's Linux results are reported in the pull request; CI remains in progress. **Overlaps and merge order:** Not checked; network access was unavailable. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
@ -211,0 +215,4 @@
/* hos_mem_region, the control bridge's one bound on what its memory reads and writes reach: a range wholly in one
region answers that region's class; one a byte past its end, one of no bytes, one that wraps past 2^64 and a
freed region answer none */
/* (two regions: the lower one's end is inside the window, so the window's own bound can't answer for it) */
Member

L1 (should fix): The new checks inherit a harness that hard-codes GCC instead of honoring the selected C compiler.

When: On a supported Windows or Linux development setup with clang available through CC but no gcc on PATH, run_all.py skips this test, or fails it in strict mode, so these new boundary checks never run.

Do: Use the test runner's {cc} compiler selection and honor CC for direct invocation, while retaining an explicit --cc override.

**L1** (should fix): The new checks inherit a harness that hard-codes GCC instead of honoring the selected C compiler. *When:* On a supported Windows or Linux development setup with clang available through CC but no gcc on PATH, run_all.py skips this test, or fails it in strict mode, so these new boundary checks never run. **Do:** Use the test runner's {cc} compiler selection and honor CC for direct invocation, while retaining an explicit --cc override.
HumanBean deleted branch test/hos-mem-region-bounds 2026-12-05 19:04:31 +00:00
Some checks are pending
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Blocked by required conditions
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Blocked by required conditions
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Blocked by required conditions
CI / What the change needs (pull_request) Blocked by required conditions
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Blocked by required conditions
CI / Third-party parts and guide screenshots (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
PR description / Title and description (pull_request_target) Successful in 8s
Some workflows are waiting to be reviewed.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!3010
No description provided.