Skip to content

fix: UB in movement path advancement - #76

Merged
ZivDero merged 4 commits into
OpenTS-Developers:mainfrom
Belonit:fix/recover-from-invalid-movement-paths
Aug 30, 2026
Merged

fix: UB in movement path advancement#76
ZivDero merged 4 commits into
OpenTS-Developers:mainfrom
Belonit:fix/recover-from-invalid-movement-paths

Conversation

@Belonit

@Belonit Belonit commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix invalid movement directions produced when locomotors advance an active path
with an overlapping memcpy.

Expected result: locomotors preserve every remaining path step and its
FACING_NONE terminator, so valid paths cannot expose uninitialized suffix
entries during movement.

The four fixes are:

  • Centralize path advancement in FootClass::Advance_Path and use memmove
    for the overlapping shift. Initialize the complete path in the constructor
    and restore a canonical FACING_NONE suffix after every advancement.
  • Validate generated-path offsets and lengths before copying them into the
    object path, and clear the regenerated suffix so failed or shorter path
    searches cannot expose stale directions.
  • Stop stationary-occupier traversal at FACING_COUNT, which marks tunnel
    movement and is not a direction accepted by Adjacent_Cell.
  • Check the path index before reading it during collision avoidance, preventing
    a separate one-past-end read when a terminator is missing.

Behavior and compatibility

Bug fix. Valid movement paths retain their existing behavior; path advancement
no longer depends on undefined overlapping-copy behavior. Maps, rules, saved
games, replays, network formats, deterministic simulation, and COM/ABI surfaces
are unchanged. No migration is required.

Validation

  • An optimized clang-cl reproducer corrupted the sentinel with overlapping
    memcpy; changing only the operation to memmove preserved it.
  • A sweep across active path lengths reproduced lost sentinels at several
    lengths with memcpy and none with memmove.
  • The affected foot.cpp translation unit compiled successfully in the
    experimental clang-cl Release configuration.
  • The supported Visual Studio 2022 Win32 Debug and Release builds were not run.

Documentation

No documentation change is needed. These are internal movement correctness
fixes that preserve the documented behavior and data formats.

Checklist

  • The change is focused; unrelated mechanical cleanup is separate
  • Compatibility effects and any migration are explicit
  • Documentation impact is stated
  • Validation distinguishes what passed, failed, and was not run
  • No prohibited assets, binaries, SDKs, credentials, or generated output are included

@Belonit Belonit mentioned this pull request Aug 29, 2026
4 tasks
@Belonit
Belonit marked this pull request as draft August 29, 2026 23:07
Evaluate the path index bound before reading blocker Path, preventing a one-past-end access when no sentinel is present.
Replace overlapping path shifts with centralized memmove-based advancement. Initialize and terminate path storage so completed steps cannot expose stale facings.
Validate path offsets and lengths before copying generated steps. Clear the regenerated suffix so paths remain terminated after success or failure.
Stop stationary-occupier traversal at FACING_COUNT, which represents a tunnel marker rather than a direction suitable for Adjacent_Cell.
@Belonit
Belonit force-pushed the fix/recover-from-invalid-movement-paths branch from cb7eea5 to b6a391e Compare August 30, 2026 11:03
@Belonit Belonit changed the title fix: recover from invalid movement paths fix: undefined behavior in movement path advancement Aug 30, 2026
@Belonit
Belonit marked this pull request as ready for review August 30, 2026 11:10
@Belonit

Belonit commented Aug 30, 2026

Copy link
Copy Markdown
Contributor Author

Updated after identifying the root cause: overlapping memcpy calls corrupted movement paths while advancing them. The fix now uses overlap-safe path advancement instead of recovering from invalid directions after corruption.

@Belonit Belonit changed the title fix: undefined behavior in movement path advancement fix: UB in movement path advancement Aug 30, 2026
@github-actions

Copy link
Copy Markdown

Development builds of b6a391e:

The links work without a GitHub account. Artifacts expire after 90 days, and this comment follows the latest successful build.

@ZivDero
ZivDero merged commit b50f3d4 into OpenTS-Developers:main Aug 30, 2026
8 of 9 checks passed
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