Skip to content

[MOD-15685] Fix crash when a legacy index spec is restored on a running server - #10872

Merged
dor-forer merged 1 commit into
masterfrom
dor-mod15685-restore-null-globals
Aug 12, 2026
Merged

dor-forer merged 1 commit into
masterfrom
dor-mod15685-restore-null-globals

Conversation

@dor-forer

Copy link
Copy Markdown
Collaborator

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_INDEX rules (legacySpecRules) and the registry of legacy specs (legacySpecDict) are built
for the duration of a load and released at the end of it — src/rules.c and src/indexes.c set both to
NULL. But IndexSpec_LegacyRdbLoad looks them up unconditionally:

SchemaRuleArgs *rule_args = dictFetchValue(legacySpecRules, sp->specName);

So a RESTORE of a legacy ft_index0 payload on a running server reaches dictFetchValue on a NULL
dict, which dereferences it in dictSize and segfaults. Reachable by any client holding RESTORE.

2. Change — refuse the load when either global is absent, before anything is read from the payload:

if (legacySpecRules == NULL || legacySpecDict == NULL) {
  RedisModule_LogIOError(rdb, "warning",
                         "Refusing to load a legacy index outside of an RDB load");
  return NULL;
}

Returning NULL is how a module reports a failed load, which for RESTORE surfaces 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 RESTORE is refused for encoding versions 2, 9 and 16 (the legacy spec range is
LEGACY_INDEX_MIN_VERSION..LEGACY_INDEX_MAX_VERSION, 2..16) and that the server is still up. I then
removed the guard again and re-ran it: the server dies and the test reports Connection refused. So it
fails when the bug is present rather than passing for the wrong reason.

Which additional issues this PR fixes

  1. MOD-15685 — with this, both Building on Mac? #29 and Support Configurable Stopwords #71 are addressed and the ticket can close

Main objects this PR modified

  1. src/spec.c — IndexSpec_LegacyRdbLoad guard
  2. tests/pytests/test_legacy_module_types.py — RESTORE of a legacy spec is refused

Mark if applicable

  • This PR introduces API changes
  • This PR introduces serialization changes

Release Notes

  • This PR requires release notes
  • This PR does not require release notes

@codecov

codecov Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.24%. Comparing base (5d87f55) to head (7d382cc).
⚠️ Report is 27 commits behind head on master.

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     
Flag Coverage Δ
flow 84.36% <100.00%> (+0.36%) ⬆️
unit 55.73% <0.00%> (-0.19%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dor-forer
dor-forer requested a review from GuyAv46 August 12, 2026 13:59
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]>
@dor-forer
dor-forer force-pushed the dor-mod15685-restore-null-globals branch from 25e4bdc to 7d382cc Compare August 12, 2026 14:12
@dor-forer
dor-forer requested a review from GuyAv46 August 12, 2026 14:14
@dor-forer
dor-forer enabled auto-merge August 12, 2026 14:44
@dor-forer
dor-forer added this pull request to the merge queue Aug 12, 2026
@sonarqubecloud

Copy link
Copy Markdown

Merged via the queue into master with commit 1d4c089 Aug 12, 2026
53 checks passed
@dor-forer
dor-forer deleted the dor-mod15685-restore-null-globals branch August 12, 2026 15:20
@kei-nan

kei-nan commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

/backport-agent 2.10

@kei-nan

kei-nan commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

/backport 2.10

@redisearch-backport-pull-request

redisearch-backport-pull-request Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

🤖 Auto-backport summary

Target Status Backport PR
2.10 conflicts(2) #11609

(PR #10872, 1d4c08915 — generated by the auto-backport workflow.)

Workflow run · Retry unfinished targets with /backport <branches>.

@kei-nan

kei-nan commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

/backport 8.2 8.4 8.6 8.6-rse 8.8 8.8-rse 8.10

@redisearch-backport-pull-request

redisearch-backport-pull-request Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

🤖 Auto-backport summary

Target Status Backport PR
8.2 conflicts(2) #11616
8.4 conflicts(1) #11615
8.6 conflicts(1) #11613
8.6-rse conflicts(1) #11614
8.8 clean #11610
8.8-rse clean #11611
8.10 clean #11612

(PR #10872, 1d4c08915 — generated by the auto-backport workflow.)

Workflow run · Retry unfinished targets with /backport <branches>.

github-merge-queue Bot pushed a commit that referenced this pull request Sep 29, 2026
…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]>
pull Bot pushed a commit to Mu-L/RediSearch that referenced this pull request Sep 29, 2026
…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]>
kei-nan added a commit that referenced this pull request Sep 30, 2026
…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)
kei-nan added a commit that referenced this pull request Sep 30, 2026
…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)
kei-nan added a commit that referenced this pull request Sep 30, 2026
…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)
kei-nan added a commit that referenced this pull request Sep 30, 2026
…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)
kei-nan added a commit that referenced this pull request Oct 1, 2026
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants