Skip to content

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

Merged
redisearch-backport-pull-request[bot] merged 1 commit into
8.4from
backport-agent/pr-10872-to-8.4
Sep 29, 2026
Merged

redisearch-backport-pull-request[bot] merged 1 commit into
8.4from
backport-agent/pr-10872-to-8.4

Conversation

@redisearch-backport-pull-request

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

Copy link
Copy Markdown
Contributor

Backport of #10872 to 8.4.

Original PR

Cherry-pick result

  • Resolved 1 conflict(s) — see Conflict Log below.

Conflict Log

src/spec.c

  • Conflict: The incoming hunk includes the new null-dictionary guard next to a SearchDisk_IsEnabled assertion; the release branch has no such assertion at this location.
  • Why it conflicted: 8.4 retains the legacy loader without the disk-mode assertion present in the source commit context. Both legacy dictionaries and their load-time lifecycle are present on this branch.
  • Resolution: Inserted the original guard and explanatory comment immediately after the encoding-version check and before the first payload read. Omitted the disk-mode assertion from the conflicting context, preserving the release loader otherwise unchanged.
  • Rationale: Rejects legacy RESTORE payloads when either dictionary is absent while preserving genuine RDB upgrades. The guard is identical to the original commit; no disk-mode behavior is introduced. Static diff and commit-provenance checks passed; builds and tests were not run, as requested.

Release notes

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

🤖 Generated by the auto-backport workflow.

…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: 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".

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.

P2 Badge 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 👍 / 👎.

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.

@kei-nan Can you check this?

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.

@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.

@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.85%. Comparing base (8f6c607) to head (a5fb359).

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              
Flag Coverage Δ
flow 84.60% <100.00%> (-0.16%) ⬇️
unit 51.32% <0.00%> (-0.01%) ⬇️

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.

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 auto-backport-conflicts There were conflicts in this automatic backport size:S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants