Repository navigation
MOD-13409 Harden RDB loading (backport to 2.6) - #1040
Conversation
* MOD-13409 Validate Bloom RDB bitset size on load (#126) * MOD-13409 Validate Bloom RDB bitset size on load Reject crafted module payloads where the loaded bloom bitset buffer length does not match the declared bits/n2, and add a flow regression test covering RESTORE with a corrupted DUMP payload. * MOD-13409 clang-format rebloom.c Run clang-format on rebloom.c to satisfy make lint formatting checks. * MOD-13409 Validate Bloom RDB bitset length on load Reject crafted module payloads where persisted bits do not match the loaded bitset buffer length, preventing OOB access after RESTORE. (cherry picked from commit ecbdc81) * Mod 13409 rdb hardening (#127) * MOD-13409 clang-format rebloom.c Run clang-format on rebloom.c to satisfy make lint formatting checks. * MOD-13409 Harden CF RDB load buffer validation Replace assert-only checks in CFRdbLoad with explicit validation of loaded sizes and ranges, and add a flow test that corrupts a CF DUMP payload to ensure RESTORE is rejected. * MOD-13409 Harden remaining RDB loaders (TDigest) TDigest RDB loading trusted attacker-controlled cap, which could desync the allocated centroid arrays from the loaded metadata and enable OOB access after RESTORE. Reject payloads where loaded cap differs from the allocated cap derived from compression, validate node counters, and add a flow regression that corrupts a TDigest DUMP payload and asserts RESTORE is rejected. With the earlier BF/CF fixes, this covers all remaining module data structures that load raw buffers from RDB/RESTORE (CMS/TopK already validate buffer sizes). * Revert "MOD-13409 clang-format rebloom.c" This reverts commit 456e53503f51b68c4d7a9df988e50a36adf2e61a. (cherry picked from commit a4b4f80)
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 66d3b3c. Configure here.
| new_crc = _crc64_redis(new_value_bytes + version) | ||
| patched = True | ||
| return new_value_bytes + version + struct.pack("<Q", new_crc) | ||
| continue |
There was a problem hiding this comment.
Test parser mismatches UINT opcode for SINT field
High Severity
The function _corrupt_dump_set_first_uint_after_3_doubles matches against RDB_MODULE_OPCODE_UINT (opcode 2) to find the cap field, but TDigest saves cap via RedisModule_SaveSigned, which emits RDB_MODULE_OPCODE_SINT (opcode 1). The SINT opcode is never defined or handled in the parser, so when parsing a TDigest dump, the function encounters opcode 1 after the three doubles and falls through to raise RuntimeError("Unknown module opcode …"). The error message at line 171 ("Did not find target SINT to patch") confirms the developer intended to target a signed integer field. The test_restore_rejects_corrupted_tdigest_cap test cannot exercise the hardening it was designed to validate.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 66d3b3c. Configure here.
Avoid signed overflow when validating merged and unmerged node counts by widening the addition.
|





Summary
Backport of #1038 to 2.6.
Testing
Note
High Risk
Changes deserialization of persisted module data; bugs could reject valid snapshots or miss edge cases, but scope is defensive validation on untrusted RDB input rather than runtime command paths.
Overview
Hardens module RDB/DUMP restore so crafted payloads are rejected instead of trusting serialized metadata or undersized buffers.
Bloom (
BFRdbLoad) adds null/empty/overflow checks on the bitset buffer, encoding-version-specific bit/buffer consistency (bitsvssztmp*8for encver > 0),n2bounds, and keeps integrity validation before use.Cuckoo (
CFRdbLoad) validatesnumFilters/numBucketsand uint16 fields against max constants, runsCuckooFilter_ValidateIntegritybefore allocating sub-filters, requires power-of-two sub-bucket counts, and replacesasserton buffer length with explicit expected-length and overflow checks.TDigest (
TDigestRdbLoad) requires loadedcapto matchtd_new()allocation, bounds node counts against that cap, and handles allocation failure.Patch version bumps to 2.6.31. New flow tests corrupt
DUMPpayloads for BF, CF, and TDigest and assertRESTOREerrors while the server stays healthy.Reviewed by Cursor Bugbot for commit fd2f766. Bugbot is set up for automated code reviews on this repo. Configure here.