Repository navigation
Fail the RDB load instead of crashing on truncated legacy document byte offsets - #11605
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]>
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1a3675c850
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (BufferReader_Remaining(&r) < numFields * fieldRecordSize + sizeof(uint32_t)) { | ||
| return NULL; |
There was a problem hiding this comment.
Exercise truncated offset headers
The added test reaches only the offsetsLen check with a structurally complete header; it does not exercise rejection of an empty blob or a field count followed by a truncated field record/data-length header. A regression in this branch could therefore restore an out-of-bounds Buffer_ReadU32 during RDB startup without failing the suite, so add malformed fixtures for both newly handled header layouts and assert the same clean load rejection.
AGENTS.md reference: AGENTS.md:L22-L22
Useful? React with 👍 / 👎.
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]>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #11605 +/- ##
==========================================
- Coverage 84.24% 83.53% -0.72%
==========================================
Files 640 665 +25
Lines 85437 86558 +1121
Branches 39264 40356 +1092
==========================================
+ Hits 71976 72305 +329
- Misses 13095 13879 +784
- Partials 366 374 +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:
|
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]>
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]>
|



Describe the changes in the pull request
DocTable_LegacyRdbLoad: truncated byte offsets for doc id <n>instead of crashing. Well-formed legacy RDBs load and upgrade as before.Which additional issues this PR fixes
Main objects this PR modified
LoadByteOffsets(src/byte_offsets.c): checks the field records, the data length and the data against the bytes remaining, and returns NULL when the blob is short.DocTable_LegacyRdbLoad(src/doc_table.c): on NULL, logs, frees the document it was building, and fails the load.IndexSpec_LegacyRdbLoad(src/spec.c) andIndexes_UpgradeLegacyIndexes(src/indexes_scan.c): the legacy spec'sIndexErroris initialized when the spec is created, soIndexSpec_Freeis safe on every failed legacy load. It is cleared before the upgrade re-initializes the stats.DocTable_LegacyRdbLoadclearsDocument_HasPayloadon a deleted document whose payload it does not load, soDMD_Freeno longer dereferences a NULL payload.test_legacy_module_types.py: builds a legacy (encver 16) index RDB in the test and starts the server from it.Mark if applicable
No format change. RDBs that used to crash the server during load are now rejected. Nothing that loaded before is rejected: blobs with trailing bytes after the data are still accepted.
Release Notes
Review notes
Why this path only. On master,
LoadByteOffsetshas one caller, the legacy (encver 2-16) doc-table loader. A legacy index can only be loaded during the first RDB load after the module loads.RESTOREof one is already refused (#10872), so the trigger is starting from, or fully syncing, an RDB file.Why
Buffer_Readis unchanged. Its bounds check is commented out and it has many readers, some of which read buffers whosecapis not their data size. The check lives in the one loader that parses untrusted lengths.Verification. Each regression test was run in fresh checkouts of
master(base, neither fix) and this branch's head, one run per test:mastercf6be819561c47d657DEBUG=1)testLegacySpecWithTruncatedByteOffsetsFailsToLoadLoadByteOffsetscalled fromDocTable_LegacyRdbLoadtestLegacySpecWithDeletedPayloadDocLoads(encver 16)DMD_Freeduring the RDB loadtestLegacySpecWithDeletedPayloadDocLoadsExpireEncoding(encver 13)DMD_Freeduring the RDB loadtestRDBCompatibilityover the bundled 1.2-2.0 RDBs and #11619's failed-syncRESTOREtest)Performance. A few length comparisons per document, only in the legacy loader, which runs once per legacy index at startup. Not measured.
Breaking changes. None identified.
Limitations.
test_aux_save2.py: the server exits mid-load by design. So the new cleanup path (freeing the partial offsets, document and spec) has no sanitizer run.startupGraceSecsand its "Redis server is dead" error text, astest_aux_save2.pydoes.MALLOC=libc, and headers not regenerated (REDISEARCH_GENERATE_HEADERS=0, safe because no Rust FFI signature changed).🤖 Generated with Claude Code