Repository navigation
[MOD-15685] Fix crash when a legacy index spec is restored on a running server - #10872
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #10872 +/- ##
==========================================
- Coverage 83.00% 82.24% -0.77%
==========================================
Files 607 630 +23
Lines 80798 82105 +1307
Branches 35690 37363 +1673
==========================================
+ Hits 67068 67526 +458
- Misses 13391 14232 +841
- Partials 339 347 +8
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:
|
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]>
25e4bdc to
7d382cc
Compare
|
|
/backport-agent 2.10 |
|
/backport 2.10 |
|
🤖 Auto-backport summary
(PR #10872, Workflow run · Retry unfinished targets with |
|
/backport 8.2 8.4 8.6 8.6-rse 8.8 8.8-rse 8.10 |
|
🤖 Auto-backport summary
(PR #10872, Workflow run · Retry unfinished targets with |
…on a running server (#11611) [MOD-15685] Fix crash when a legacy index spec is restored on a running 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. (cherry picked from commit 1d4c089) Co-authored-by: dor-forer <[email protected]> Co-authored-by: Claude Opus 5 <[email protected]>
…iled replication sync (RediSearch#11619) [MOD-15685] Refuse a legacy index spec RESTORE after a failed load The guard added in RediSearch#10872 refused a legacy ft_index0 load when the legacy-spec registry or the UPGRADE_INDEX rules were NULL, taking that as "no load in progress". A failed load breaks that assumption: LOADING_FAILED clears the loading flag but frees neither global, and the rules are only ever freed by a successful load. On a server that has not completed a load since startup - for example a replica whose first full sync failed and was then promoted - a RESTORE of a truncated legacy payload got past the guard and crashed on the NULL spec name. Key the refusal on g_isLoading as well. The new test drives exactly that sequence against a fake master; it crashes the server without the fix. Co-authored-by: Claude Opus 5.5 <[email protected]>
…iled replication sync (#11619) [MOD-15685] Refuse a legacy index spec RESTORE after a failed load The guard added in #10872 refused a legacy ft_index0 load when the legacy-spec registry or the UPGRADE_INDEX rules were NULL, taking that as "no load in progress". A failed load breaks that assumption: LOADING_FAILED clears the loading flag but frees neither global, and the rules are only ever freed by a successful load. On a server that has not completed a load since startup - for example a replica whose first full sync failed and was then promoted - a RESTORE of a truncated legacy payload got past the guard and crashed on the NULL spec name. Key the refusal on g_isLoading as well. The new test drives exactly that sequence against a fake master; it crashes the server without the fix. Co-authored-by: Claude Opus 5.5 <[email protected]> (cherry picked from commit b1b6903)
…iled replication sync (#11619) [MOD-15685] Refuse a legacy index spec RESTORE after a failed load The guard added in #10872 refused a legacy ft_index0 load when the legacy-spec registry or the UPGRADE_INDEX rules were NULL, taking that as "no load in progress". A failed load breaks that assumption: LOADING_FAILED clears the loading flag but frees neither global, and the rules are only ever freed by a successful load. On a server that has not completed a load since startup - for example a replica whose first full sync failed and was then promoted - a RESTORE of a truncated legacy payload got past the guard and crashed on the NULL spec name. Key the refusal on g_isLoading as well. The new test drives exactly that sequence against a fake master; it crashes the server without the fix. Co-authored-by: Claude Opus 5.5 <[email protected]> (cherry picked from commit b1b6903)
…iled replication sync (#11619) [MOD-15685] Refuse a legacy index spec RESTORE after a failed load The guard added in #10872 refused a legacy ft_index0 load when the legacy-spec registry or the UPGRADE_INDEX rules were NULL, taking that as "no load in progress". A failed load breaks that assumption: LOADING_FAILED clears the loading flag but frees neither global, and the rules are only ever freed by a successful load. On a server that has not completed a load since startup - for example a replica whose first full sync failed and was then promoted - a RESTORE of a truncated legacy payload got past the guard and crashed on the NULL spec name. Key the refusal on g_isLoading as well. The new test drives exactly that sequence against a fake master; it crashes the server without the fix. Co-authored-by: Claude Opus 5.5 <[email protected]> (cherry picked from commit b1b6903)
…iled replication sync (#11619) [MOD-15685] Refuse a legacy index spec RESTORE after a failed load The guard added in #10872 refused a legacy ft_index0 load when the legacy-spec registry or the UPGRADE_INDEX rules were NULL, taking that as "no load in progress". A failed load breaks that assumption: LOADING_FAILED clears the loading flag but frees neither global, and the rules are only ever freed by a successful load. On a server that has not completed a load since startup - for example a replica whose first full sync failed and was then promoted - a RESTORE of a truncated legacy payload got past the guard and crashed on the NULL spec name. Key the refusal on g_isLoading as well. The new test drives exactly that sequence against a fake master; it crashes the server without the fix. Co-authored-by: Claude Opus 5.5 <[email protected]> (cherry picked from commit b1b6903)
…iled replication sync (#11619) [MOD-15685] Refuse a legacy index spec RESTORE after a failed load The guard added in #10872 refused a legacy ft_index0 load when the legacy-spec registry or the UPGRADE_INDEX rules were NULL, taking that as "no load in progress". A failed load breaks that assumption: LOADING_FAILED clears the loading flag but frees neither global, and the rules are only ever freed by a successful load. On a server that has not completed a load since startup - for example a replica whose first full sync failed and was then promoted - a RESTORE of a truncated legacy payload got past the guard and crashed on the NULL spec name. Key the refusal on g_isLoading as well. The new test drives exactly that sequence against a fake master; it crashes the server without the fix. Co-authored-by: Claude Opus 5.5 <[email protected]> (cherry picked from commit b1b6903)



Describe the changes in the pull request
Closes the second half of MOD-15685. Finding #29 (legacy keys could not be persisted) was fixed in
#10817; this is finding #71, and with it the ticket can be closed.
1. Current — a legacy index spec can only be upgraded while an RDB load is in progress. Both the
UPGRADE_INDEXrules (legacySpecRules) and the registry of legacy specs (legacySpecDict) are builtfor the duration of a load and released at the end of it —
src/rules.candsrc/indexes.cset both toNULL. But
IndexSpec_LegacyRdbLoadlooks them up unconditionally:So a
RESTOREof a legacyft_index0payload on a running server reachesdictFetchValueon a NULLdict, which dereferences it in
dictSizeand segfaults. Reachable by any client holdingRESTORE.2. Change — refuse the load when either global is absent, before anything is read from the payload:
Returning NULL is how a module reports a failed load, which for
RESTOREsurfaces as a command error.Placing the check before any read means a crafted payload needs no valid body to be rejected.
3. Outcome — restoring a legacy index spec is a clean command error instead of a dead shard. The
genuine upgrade path is untouched: during a real RDB load both globals exist, so the check passes.
Verification
The new test asserts
RESTOREis refused for encoding versions 2, 9 and 16 (the legacy spec range isLEGACY_INDEX_MIN_VERSION..LEGACY_INDEX_MAX_VERSION, 2..16) and that the server is still up. I thenremoved the guard again and re-ran it: the server dies and the test reports
Connection refused. So itfails when the bug is present rather than passing for the wrong reason.
Which additional issues this PR fixes
Main objects this PR modified
src/spec.c—IndexSpec_LegacyRdbLoadguardtests/pytests/test_legacy_module_types.py— RESTORE of a legacy spec is refusedMark if applicable
Release Notes