Skip to content

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

Merged
kei-nan merged 1 commit into
8.10from
backport-agent/pr-10872-to-8.10
Sep 30, 2026
Merged

kei-nan merged 1 commit into
8.10from
backport-agent/pr-10872-to-8.10

Conversation

@redisearch-backport-pull-request

Copy link
Copy Markdown
Contributor

Backport of #10872 to 8.10.
Merge commit: 1d4c08915f3cc628098679fc2286a47483d77599

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

…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)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5c785edb10

ℹ️ 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".

Comment thread src/spec.c
// 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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Require an active RDB load, not merely allocated staging dictionaries

After a non-disk RDB/AOF/replication load fails, the LOADING_FAILED handler does not call Indexes_EndRDBLoadingEvent, so legacySpecDict and the configured legacySpecRules remain allocated even though Indexes_EndLoading() has marked loading complete. A subsequent client RESTORE of a valid legacy ft_index0 payload therefore passes this predicate and enters the legacy loader; with a matching UPGRADE_INDEX rule it installs a legacy spec into the staging dictionary, but there will be no loading-ended upgrade sweep to publish or clean it up. Gate this on actual loading state (or release the non-disk legacy staging state on LOADING_FAILED) so the refusal also holds after a failed load.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Valid, and also present on master. A failed load leaves both globals allocated, so this guard is bypassed until the next successful load. With a truncated payload that still crashes, not just leaks. Fixed on master in #11619 (the refusal now also requires g_isLoading, plus a regression test). It will be backported to this branch once it merges, so this backport stays identical to #10872.

@sonarqubecloud

Copy link
Copy Markdown

@redisearch-backport-pull-request
redisearch-backport-pull-request Bot added this pull request to the merge queue Sep 29, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 29, 2026
@kei-nan
kei-nan added this pull request to the merge queue Sep 30, 2026
Merged via the queue into 8.10 with commit e82cc2d Sep 30, 2026
38 checks passed
@kei-nan
kei-nan deleted the backport-agent/pr-10872-to-8.10 branch September 30, 2026 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport This PR was automatically backported by an agent size:S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants