Repository navigation
MOD-13409 Harden RDB loading (backport to 8.6) - #1046
Conversation
* 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.
* 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.
| raise RuntimeError(f"Unknown module opcode {opcode} at pos={pos}") | ||
|
|
||
| if not patched: | ||
| raise RuntimeError("Did not find target SINT to patch") |
There was a problem hiding this comment.
Test helper missing SINT opcode breaks TDigest test
High Severity
The _corrupt_dump_set_first_uint_after_3_doubles function only handles RDB_MODULE_OPCODE_UINT (2), RDB_MODULE_OPCODE_DOUBLE (4), RDB_MODULE_OPCODE_STRING (5), and RDB_MODULE_OPCODE_EOF (0). However, TDigest saves cap via RedisModule_SaveSigned, which writes RDB_MODULE_OPCODE_SINT (opcode 1). When parsing the TDigest payload after the three doubles (compression, min, max), the parser encounters opcode 1 (SINT) and raises RuntimeError("Unknown module opcode 1") instead of patching the cap value. This means test_restore_rejects_corrupted_tdigest_cap cannot produce a valid corrupted payload and doesn't actually test the hardened loading code.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 06364be. Configure here.
| errdefer(err, td_free(tdigest)); | ||
| if (tdigest == NULL) { | ||
| err = true; | ||
| return NULL; |
There was a problem hiding this comment.
errdefer calls td_free on NULL tdigest pointer
Medium Severity
The errdefer on line 880 registers td_free(tdigest) as cleanup before the NULL check on line 881. When td_new returns NULL, setting err = true and returning triggers the errdefer, which calls td_free(NULL). Since td_free typically dereferences its argument to free internal arrays (nodes_mean, nodes_weight), this results in a NULL pointer dereference crash during error cleanup.
Reviewed by Cursor Bugbot for commit bcc0df2. Configure here.
Avoid signed overflow when validating merged and unmerged node counts by widening the addition.
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
There are 3 total unresolved issues (including 2 from previous reviews).
❌ 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 c5b2409. Configure here.
| _lzf_decompress(comp, ulen) | ||
| pos = comp_end | ||
| continue | ||
| raise RuntimeError(f"Unknown module opcode {opcode} at pos={pos}") |
There was a problem hiding this comment.
Test parser missing SINT opcode handling for TDigest
Medium Severity
The _corrupt_dump_set_first_uint_after_3_doubles function only handles RDB_MODULE_OPCODE_UINT (2), RDB_MODULE_OPCODE_DOUBLE (4), RDB_MODULE_OPCODE_STRING (5), and RDB_MODULE_OPCODE_EOF (0). It does not handle RDB_MODULE_OPCODE_SINT (1). TDigestRdbSave uses RedisModule_SaveSigned for cap, merged_nodes, etc., which emits a SINT opcode. When the parser encounters this opcode after the 3 doubles, it falls through to the raise RuntimeError catch-all, preventing the TDigest corruption test from functioning.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit c5b2409. Configure here.
## Summary Bumps the RedisBloom pin on `8.6` from `v8.6.2` to `v8.6.5`. | Module | From | To | |---|---|---| | RedisBloom | `v8.6.2` | `v8.6.5` | ## RedisBloom changes ([v8.6.2...v8.6.5](RedisBloom/RedisBloom@v8.6.2...v8.6.5)) - MOD-16050 — Replicate `CF.LOADCHUNK` data chunks to prevent silent Cuckoo Filter data loss on failover ([#1021](RedisBloom/RedisBloom#1021)) - MOD-13409 — Harden RDB loading, including validation of crafted module payloads ([#1046](RedisBloom/RedisBloom#1046)) ## Test plan - [x] Confirmed `v8.6.5` exists in RedisBloom - [x] Validated `modules/redisbloom/Makefile` pins `MODULE_VERSION` to `v8.6.5` - [ ] Redis core CI passes with the updated module pin <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Upstream changes affect replication and persistence loading for Bloom/Cuckoo data; risk is confined to the version pin but runtime behavior shifts on upgrade. > > **Overview** > **Bumps the RedisBloom build pin** from `v8.6.2` to `v8.6.5` in `modules/redisbloom/Makefile` (`MODULE_VERSION` only). > > That upstream release brings **replication for `CF.LOADCHUNK`** so Cuckoo Filter chunks aren’t lost on failover, plus **stricter RDB load validation** for crafted module payloads. No other files in this repo change—consumers get the new `.so` when rebuilt against this pin. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit e3b8bc5. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->





Summary
Backport of #1038 to 8.6.
Testing
Note
High Risk
Changes deserialization of untrusted RDB/RESTORE data; failures are safer, but any overly strict check could reject valid snapshots—high impact because bugs here are memory-safety issues.
Overview
Hardens RESTORE/RDB load for Bloom filters, Cuckoo filters, and T-Digest so crafted or truncated module payloads are rejected instead of trusting metadata alone.
Bloom (
BFRdbLoad): rejects missing/empty/oversized bitset buffers; for newer encodings requiresbitsto match buffer size × 8; validatesn2and related bit geometry beforebloom_validate_integrity.Cuckoo (
CFRdbLoad): bounds-checks filter/bucket counts and fields that map touint16_t; runsCuckooFilter_ValidateIntegritybefore sub-filter allocation; validates per-subfilter bucket counts (non-zero, power-of-two, max) and that each serialized bucket blob length matchesbucketSize × numBuckets; replacesassert-only checks with explicit load failures.T-Digest (
TDigestRdbLoad): ensures loadedcapmatches whattd_new(compression)allocated and tightens checks on merged/unmerged node counts relative to that cap.Patch release 8.6.5 and new flow tests corrupt
DUMPpayloads (shrunk bitset/bucket strings, inflated TDigest cap) and assertRESTOREerrors while the original keys stay usable.Reviewed by Cursor Bugbot for commit c5b2409. Bugbot is set up for automated code reviews on this repo. Configure here.