Skip to content

MoqxCache: fix two updateInProgress UB/crash bugs#303

Merged
afrind merged 1 commit intomainfrom
fix/moqx-cache-update-in-progress
May 8, 2026
Merged

MoqxCache: fix two updateInProgress UB/crash bugs#303
afrind merged 1 commit intomainfrom
fix/moqx-cache-update-in-progress

Conversation

@afrind
Copy link
Copy Markdown
Contributor

@afrind afrind commented May 8, 2026

Branch 3 of updateInProgress() erases the fetchesInProgress entry and sets fetchInProgressIt_=end(). Two distinct bugs follow from this:

  1. XCHECK crash (boundary collision): the previous re-key logic would attempt to re-key to maxLocation even when a concurrent fetch had already inserted an entry there. Fix: skip re-key when current >= maxLocation (erase-only), and guard the post-erase path so a second call from endOfFetch() doesn't attempt re-key on end().

  2. UB dereference (double call): fetchInProgressIt_->second.progress was updated before the fetchInProgressIt_ != end() guard, so a second updateInProgress() call (e.g. endOfFetch() after a finFetch=true object) would dereference end(), corrupting the map sentinel. Fix: hoist the guard to cover the progress update, and add a matching guard to the else branch.

Add regression tests for both scenarios. The double-call test was verified to abort via a temporary XCHECK before the structural fix.


This change is Reviewable

Copy link
Copy Markdown
Contributor

@suhasHere suhasHere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@suhasHere reviewed 2 files and all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on akash-a-n, gmarzot, michalhosna, mondain, Oxyd, peterchave, and TimEvens).

Branch 3 of updateInProgress() erases the fetchesInProgress entry and
sets fetchInProgressIt_=end(). Two distinct bugs follow from this:

1. XCHECK crash (boundary collision): the previous re-key logic would
   attempt to re-key to maxLocation even when a concurrent fetch had
   already inserted an entry there. Fix: skip re-key when
   current >= maxLocation (erase-only), and guard the post-erase path
   so a second call from endOfFetch() doesn't attempt re-key on end().

2. UB dereference (double call): fetchInProgressIt_->second.progress
   was updated before the fetchInProgressIt_ != end() guard, so a
   second updateInProgress() call (e.g. endOfFetch() after a
   finFetch=true object) would dereference end(), corrupting the map
   sentinel. Fix: hoist the guard to cover the progress update, and add
   a matching guard to the else branch.

Add regression tests for both scenarios. The double-call test was
verified to abort via a temporary XCHECK before the structural fix.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@afrind afrind force-pushed the fix/moqx-cache-update-in-progress branch from d2a00e6 to bf020bf Compare May 8, 2026 13:46
Copy link
Copy Markdown
Contributor

@gmarzot gmarzot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gmarzot reviewed 2 files and all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on akash-a-n, michalhosna, mondain, Oxyd, peterchave, and TimEvens).

@afrind afrind merged commit a4a065a into main May 8, 2026
12 checks passed
@afrind afrind deleted the fix/moqx-cache-update-in-progress branch May 8, 2026 14:16
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.

3 participants