Repository navigation
[8.4] [MOD-15685] Fix crash when a legacy index spec is restored on a running server - #11615
Conversation
…ng server (#10872) [MOD-15685] Refuse a legacy index spec RESTORE outside an RDB load A legacy index spec can only be upgraded while a load is in progress: both the UPGRADE_INDEX rules and the registry of legacy specs are built for the duration of a load and released at the end of it. IndexSpec_LegacyRdbLoad then looks both up unconditionally, so restoring a legacy ft_index0 payload on a running server reached dictFetchValue on a NULL dict and segfaulted. Any client holding RESTORE could do it. Refuse when either global is absent. The caller sees a load failure, which for RESTORE surfaces as a command error rather than a dead server. The check sits before anything is read, so a crafted payload needs no valid body to be rejected. Verified by removing the guard again: the server dies with the test reporting connection refused, so the test fails when the bug is present rather than passing for the wrong reason. This is MOD-15685 finding #71; #29 was fixed in #10817. Co-authored-by: Claude Opus 5 <[email protected]> (cherry picked from commit 1d4c089)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a5fb359820
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // of it, so outside one - a RESTORE of a legacy payload on a running server, say - they are NULL and | ||
| // the lookups below would dereference NULL. Refuse instead: the caller sees a load failure, which for | ||
| // RESTORE surfaces as a command error. | ||
| if (legacySpecRules == NULL || legacySpecDict == NULL) { |
There was a problem hiding this comment.
Reject legacy restores after a failed load
After a failed loading event, Indexes_LoadingEvent sets g_isLoading false but does not release either dictionary. Thus, when an unused UPGRADE_INDEX rule remains (for example, after dynamically loading the module before a failed full sync), a subsequent valid RESTORE of the matching legacy spec passes this null-only check even though no load is active. The loader then creates a legacy spec that is never upgraded into specDict_g, while its key free callback is a no-op, leaving hidden/leaked index state; gate on active loading state (and/or clean up failed-load state) rather than dictionary non-nullness.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
@dor-forer Checked it, and the finding is valid. It's actually worse than a leak. LOADING_FAILED clears g_isLoading but frees neither legacySpecDict nor legacySpecRules, and the rules are only freed by a successful load. So on a server that hasn't completed a load since startup (for example a replica whose first full sync failed and was then promoted), a truncated legacy payload gets past this guard and crashes on the NULL name, just as it did before #10872. I reproduced the crash with the guard in place.
The same gap is on master, so I fixed it there: #11619 also refuses when !g_isLoading, and adds a test that fails a full sync against a fake master and then restores. It crashes without the fix and passes with it. Once it merges I'll backport it to the same branches as #10872. This PR still closes the common case on its own, so it's fine to merge as is.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 8.4 #11615 +/- ##
==========================================
- Coverage 85.91% 85.85% -0.07%
==========================================
Files 341 341
Lines 55100 55103 +3
Branches 11117 11117
==========================================
- Hits 47340 47307 -33
- Misses 7617 7653 +36
Partials 143 143
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|



Backport of #10872 to
8.4.Original PR
1d4c08915f3cc628098679fc2286a47483d77599Cherry-pick result
Conflict Log
src/spec.cRelease notes
🤖 Generated by the auto-backport workflow.