Skip to content

Fix crash loading a legacy RDB with a deleted document flagged as having a payload - #11607

Merged
eyalrund merged 3 commits into
eyalrund-fix-legacy-byte-offsets-loadfrom
eyalrund-fix-legacy-deleted-payload-load
Sep 29, 2026
Merged

eyalrund merged 3 commits into
eyalrund-fix-legacy-byte-offsets-loadfrom
eyalrund-fix-legacy-deleted-payload-load

Conversation

@eyalrund

@eyalrund eyalrund commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #11605, which adds the legacy-RDB test helpers this test uses. Review only the top three commits; 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 a pre-2.0 index, a document that is marked deleted and flagged as having a payload crashes the server during the load. The loader skips the payload of deleted documents but leaves the flag set, so freeing the dropped document dereferences a NULL payload.
  2. Change: the legacy doc-table loader clears the payload flag on a deleted document whose payload it does not load.
  3. Outcome: such RDBs load. The deleted document is dropped as before, and the legacy index upgrades.

Which additional issues this PR fixes

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

Main objects this PR modified

  1. DocTable_LegacyRdbLoad (src/doc_table.c): clears Document_HasPayload on deleted documents, whose payload is never loaded. Encver 13 still consumes the saved payload string as before.
  2. test_legacy_module_types.py: new testLegacySpecWithDeletedPayloadDocLoads (encver 16) and testLegacySpecWithDeletedPayloadDocLoadsExpireEncoding (encver 13, where the deleted document also carries its saved payload string). Each starts the server from a legacy index RDB whose only document is deleted and payload-flagged. The legacy-spec fixture now takes an encoding version.

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 DMD_Free. The loader is what leaves the flag and the pointer out of agreement. DMD_Free is shared by every document-freeing path, and there it is a valid invariant that a set flag means the payload exists.

Related, already fixed. DocTable_SetPayload writing a payload into a document allocated without a payload slot was fixed on master by #11384 (Document_HasPayloadSlot). This PR covers the remaining loader case.

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

Check Base Fix
Build (DEBUG=1) passed passed
testLegacySpecWithDeletedPayloadDocLoads (encver 16) failed as expected: SIGSEGV in DMD_Free during the RDB load passed
testLegacySpecWithDeletedPayloadDocLoadsExpireEncoding (encver 13) failed as expected: SIGSEGV in DMD_Free during the RDB load passed
Existing legacy and RDB-compatibility tests, including testRDBCompatibility over the bundled 1.2-2.0 RDBs passed passed
Independent review passed, 0 actionable

Final runs: base = #11605 tip 1a3675c85, fix = 0f0a819ff, one run per regression test. The encver-16 test was also run earlier against master a26c6a597. Separately, a build that drops the encver-13 string read fails the encver-13 test: Redis rejects the RDB because the fields after it are misread.

Performance. One flag update per deleted payload-flagged document, in the legacy loader only. Not measured.

Breaking changes. None identified.

Limitations.

  • The test is not skipped under ASan, but this verification ran a non-sanitized build; CI's sanitizer job is the first ASan run of the new test.
  • 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 2 commits September 29, 2026 13:29
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]>
@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-09-29T11:18:52.847064Z 0f0a819 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.

@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: c9e6922b96

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

Comment thread src/doc_table.c
Comment on lines +528 to +529
if (encver == INDEX_MIN_EXPIRE_VERSION) {
RedisModule_Free(RedisModule_LoadStringBuffer(rdb, NULL)); // throw this string to garbage

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 Exercise the encver-13 deleted-payload branch

The new fixture hard-codes encoding version 16 with an empty tail, leaving the version-13 compatibility path untested. Version 13 uniquely requires this changed branch to both clear Document_HasPayload and consume the serialized payload string; if either operation regresses, subsequent RDB fields are parsed out of alignment. Add an encver-13 fixture containing a module-string payload and assert that startup succeeds, the upgraded index exists, and it has zero documents.

AGENTS.md reference: AGENTS.md:L22-L22

Useful? React with 👍 / 👎.

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]>
@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.52%. Comparing base (1a3675c) to head (0f0a819).

Additional details and impacted files
@@                          Coverage Diff                           @@
##           eyalrund-fix-legacy-byte-offsets-load   #11607   +/-   ##
======================================================================
  Coverage                                  83.51%   83.52%           
======================================================================
  Files                                        665      665           
  Lines                                      86545    86546    +1     
  Branches                                   40356    40356           
======================================================================
+ Hits                                       72281    72287    +6     
+ Misses                                     13890    13885    -5     
  Partials                                     374      374           
Flag Coverage Δ
flow 84.61% <100.00%> (+<0.01%) ⬆️
unit 58.96% <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.

@sonarqubecloud

Copy link
Copy Markdown

@eyalrund
eyalrund merged commit 691a4fd into eyalrund-fix-legacy-byte-offsets-load Sep 29, 2026
62 checks passed
@eyalrund
eyalrund deleted the eyalrund-fix-legacy-deleted-payload-load branch September 29, 2026 12:27
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.

1 participant