Skip to content

Fix mb_update_arrayptr() false matches after array reallocation - #1

Open
spatial-dan wants to merge 2 commits into
masterfrom
fix-mb-update-arrayptr
Open

Fix mb_update_arrayptr() false matches after array reallocation#1
spatial-dan wants to merge 2 commits into
masterfrom
fix-mb-update-arrayptr

Conversation

@spatial-dan

Copy link
Copy Markdown

Prevent mb_update_arrayptr() from rebinding a registered array to the wrong allocation when the allocator reuses an address from an earlier reallocation cycle. The mb_update_arrayptr() matched arrays using values retained in regarray_oldptr[]. Those values could outlive their reallocation cycle. If the allocator later reused one of those addresses, a local pointer—such as a sidescan longitude array—could falsely match an earlier bathymetry registration and be rebound to the wrong buffer.

Fix

  • Clear saved pointer values at the start of each mb_update_arrays() cycle.
  • Prefer the stable registered pointer-variable address when resolving a handle.
  • Fall back to the saved pre-reallocation pointer for local copies used by mb_read(), mb_get(), and mb_get_all().
  • Clear saved pointer values after successful matches.

Added tests covering:

  • simultaneous bathymetry and sidescan growth
  • registered-handle matching in the presence of a stale collision
  • a deterministic stale-address collision across staged reallocations

Danny Neville added 2 commits August 29, 2026 00:29
Matching registered arrays by stale data pointers allowed a recycled
heap address to rebind sidescan locals (sslon) to a bathymetry buffer.
Make the staged bathymetry and sidescan case deterministic by injecting a stale pointer collision before the sidescan reallocation. This
directly verifies that mb_update_arrays() clears saved pointer values between reallocation cycles.
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