Skip to content

Fix crash loading a legacy RDB index whose fields were saved without a path - #11630

Merged
eyalrund merged 13 commits into
masterfrom
eyalrund-fix-legacy-field-path-load
Oct 1, 2026
Merged

eyalrund merged 13 commits into
masterfrom
eyalrund-fix-legacy-field-path-load

Conversation

@eyalrund

@eyalrund eyalrund commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #11605, which (with #11607 merged into it) adds the legacy-RDB test helpers this test uses. Review only this PR's three commits; the merge commit only brings in #11605's branch. This PR retargets to master once #11605 merges.

Describe the changes in the pull request

  1. Current: when Redis starts from an RDB file (or a replica runs a full sync) that holds an index saved in a legacy encoding older than version 8, and that index has at least one field, the server crashes during the load. Those encodings store a field's name but no path. The loader left the path NULL, and building the spec's field cache then dereferenced it.
  2. Change: the legacy field loader uses the field's name as its path, as every other way of creating a field already does.
  3. Outcome: such RDBs load. The upgraded index reports and indexes the field, and it survives a later save and reload.

Which additional issues this PR fixes

  1. Internal reference F-007
  2. N/A

Main objects this PR modified

  1. FieldSpec_RdbLoadCompat8 (src/spec.c): sets fieldPath to fieldName. It also hands the loaded name buffer to its HiddenString (takeOwnership = false, as FieldSpec_RdbLoad does) instead of copying it. The copy leaked the buffer, which only became reachable once these loads stopped crashing.
  2. test_legacy_module_types.py:
    • new testLegacySpecWithoutFieldPathLoads, which starts the server from an encver-7 index RDB with one TEXT field;
    • the legacy-spec fixture can now take a complete spec body;
    • the fixture now stores the spec under its real key, idx:<name>, so the upgrade removes it as it would in a real RDB.

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

Review notes

Why the loader and not the cache builder. A field with no separate path uses its name as its path everywhere else: FT.CREATE, and the current FieldSpec_RdbLoad. Only this legacy loader broke that. Guarding the NULL in IndexSpec_BuildSpecCache would stop this particular crash but leave a NULL path for every later reader: indexing reads the hash field by its path, FT.INFO reports it, and FieldSpec_RdbSave compares it with the name.

Ownership. Aliasing the path to the name is how the current loader and FT.CREATE already represent a field with no separate path. FieldSpec_Cleanup and the field-cache free skip fieldPath when it equals fieldName, so there is no double free.

Verification. The new test was run in fresh checkouts of the unfixed base and the fix:

Check Base: #11605 head 61c47d657 Head 067a3de8d
Build (DEBUG=1) passed passed
testLegacySpecWithoutFieldPathLoads failed as expected: SIGSEGV in HiddenString_Duplicate during the RDB load passed: the field is reported and indexed, including after a save and reload
Existing legacy and RDB-compatibility tests (10, including testRDBCompatibility, the tests from #11605, and #11619's failed-sync RESTORE test) 10 passed 10 passed
Independent review passed, 0 actionable

Performance. One pointer assignment per field, in the legacy loader only. Not measured.

Breaking changes. None identified.

Limitations.

  • The test covers encver 7 only. Encvers 2 to 6 take the same loader with fewer fields.
  • The test environment differs from CI: Redis 8.10-m03 built with MALLOC=libc, and headers not regenerated (REDISEARCH_GENERATE_HEADERS=0).

🤖 Generated with Claude Code

eyalrund and others added 8 commits September 29, 2026 12:39
Build a legacy (encver 16) index spec RDB file in the test and start the
server from it. One test checks that byte offsets which exactly fill
their blob load and upgrade. The other gives the offsets a length prefix
larger than the blob, which must fail the load with a diagnostic rather
than crash the server.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
LoadByteOffsets trusted the counts and lengths in the serialized blob,
so a blob shorter than its own length prefix made it read past the end
of the buffer, after allocating as much as the prefix claimed. Check
each read against the bytes remaining and return NULL when the blob is
short. DocTable_LegacyRdbLoad, its only caller, now logs and fails the
load in that case.

Failing the load also needs the legacy spec's cleanup to be safe:
IndexSpec_LegacyRdbLoad never initialized the spec's IndexError, so
freeing the spec on any load error hit an assertion (debug) or a NULL
dereference (release). Initialize it when the spec is created, and
clear it before the legacy upgrade reinitializes the stats.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build a legacy (encver 16) index spec RDB file in the test and start the
server from it. Its only document is deleted and flagged as having a
payload; the load must drop it and upgrade the index.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
DocTable_LegacyRdbLoad does not load the payload of a deleted document,
but it left Document_HasPayload set on it. Freeing the dropped document
then dereferenced its NULL payload in DMD_Free and crashed the server
during the RDB load. Clear the flag when the payload is not loaded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Encver 13 is the only encoding that saved the payload of a deleted doc,
so its load has to skip that string as well as clear the payload flag.
Parameterize the legacy spec fixture by encoding version and cover it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Encodings older than 8 store a field's name but no path. Build an
encver 7 index spec RDB file with one TEXT field, start the server from
it, and check that the upgraded index reports and serves the field, also
after saving it in the current format and reloading.

Store the fixture's legacy spec under idx:<name>, the key the upgrade
deletes, instead of a plain name the upgrade left behind.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
FieldSpec_RdbLoadCompat8, the loader for encodings older than 8, set a
field's name but left its path NULL. Everywhere else a field without a
separate path uses its name as the path, and IndexSpec_BuildSpecCache
relies on that: it duplicates the path whenever it is not the name,
so a NULL path crashed the server during the RDB load. Set the path to
the name when loading these fields.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-01T08:46:48.973454Z a2d9bcc New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

eyalrund and others added 2 commits September 29, 2026 18:26
Resolve the conflict in test_legacy_module_types.py by keeping both the
legacy-loader tests from this branch and the failed-sync RESTORE test from
master (#11619).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…field-path-load

Pick up master (via #11605's branch) and resolve the conflict in
test_legacy_module_types.py by keeping both this branch's test and
master's failed-sync RESTORE test (#11619).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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 83.55%. Comparing base (938a026) to head (a2d9bcc).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #11630      +/-   ##
==========================================
- Coverage   84.27%   83.55%   -0.72%     
==========================================
  Files         640      665      +25     
  Lines       85483    86595    +1112     
  Branches    39264    40358    +1094     
==========================================
+ Hits        72040    72355     +315     
- Misses      13078    13867     +789     
- Partials      365      373       +8     
Flag Coverage Δ
flow 84.50% <100.00%> (-0.15%) ⬇️
unit 58.95% <0.00%> (-0.42%) ⬇️

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.

FieldSpec_RdbLoadCompat8 read each field name into an allocated buffer
and passed it to NewHiddenString with takeOwnership set, which copies
the buffer rather than adopting it, so the loaded buffer leaked.
FieldSpec_RdbLoad hands the buffer over instead (takeOwnership false),
and FieldSpec_Cleanup frees it; do the same. The leak became reachable
once loading these fields stopped crashing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Base automatically changed from eyalrund-fix-legacy-byte-offsets-load to master September 30, 2026 11:44
…-field-path-load

# Conflicts:
#	tests/pytests/test_legacy_module_types.py
…-field-path-load

# Conflicts:
#	tests/pytests/test_legacy_module_types.py
@eyalrund
eyalrund requested a review from Itzikvaknin October 1, 2026 08:49
@sonarqubecloud

sonarqubecloud Bot commented Oct 1, 2026

Copy link
Copy Markdown

@eyalrund
eyalrund requested a review from kei-nan October 1, 2026 11:16
Comment thread src/spec.c Resolved
@eyalrund
eyalrund added this pull request to the merge queue Oct 1, 2026
Merged via the queue into master with commit 10e4991 Oct 1, 2026
61 checks passed
@eyalrund
eyalrund deleted the eyalrund-fix-legacy-field-path-load branch October 1, 2026 13:09
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.

2 participants