Repository navigation
Fix crash loading a legacy RDB index whose fields were saved without a path - #11630
Conversation
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]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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 Report✅ All modified and coverable lines are covered by tests. 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
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:
|
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]>
…-field-path-load # Conflicts: # tests/pytests/test_legacy_module_types.py
…-field-path-load # Conflicts: # tests/pytests/test_legacy_module_types.py
|



Describe the changes in the pull request
Which additional issues this PR fixes
Main objects this PR modified
FieldSpec_RdbLoadCompat8(src/spec.c): setsfieldPathtofieldName. It also hands the loaded name buffer to itsHiddenString(takeOwnership = false, asFieldSpec_RdbLoaddoes) instead of copying it. The copy leaked the buffer, which only became reachable once these loads stopped crashing.test_legacy_module_types.py:testLegacySpecWithoutFieldPathLoads, which starts the server from an encver-7 index RDB with one TEXT field;idx:<name>, so the upgrade removes it as it would in a real RDB.Mark if applicable
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 currentFieldSpec_RdbLoad. Only this legacy loader broke that. Guarding the NULL inIndexSpec_BuildSpecCachewould stop this particular crash but leave a NULL path for every later reader: indexing reads the hash field by its path,FT.INFOreports it, andFieldSpec_RdbSavecompares it with the name.Ownership. Aliasing the path to the name is how the current loader and
FT.CREATEalready represent a field with no separate path.FieldSpec_Cleanupand the field-cache free skipfieldPathwhen it equalsfieldName, so there is no double free.Verification. The new test was run in fresh checkouts of the unfixed base and the fix:
61c47d657067a3de8dDEBUG=1)testLegacySpecWithoutFieldPathLoadsHiddenString_Duplicateduring the RDB loadtestRDBCompatibility, the tests from #11605, and #11619's failed-syncRESTOREtest)Performance. One pointer assignment per field, in the legacy loader only. Not measured.
Breaking changes. None identified.
Limitations.
MALLOC=libc, and headers not regenerated (REDISEARCH_GENERATE_HEADERS=0).🤖 Generated with Claude Code