Repository navigation
MOD-13409 Harden RDB loading (backport to 8.10) - #1042
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.
| new_value_bytes = value[:val_start] + encoded + value[val_end:] | ||
| new_crc = _crc64_redis(new_value_bytes + version) | ||
| patched = True | ||
| return new_value_bytes + version + struct.pack("<Q", new_crc) |
There was a problem hiding this comment.
Test matches UINT opcode instead of SINT for TDigest
High Severity
_corrupt_dump_set_first_uint_after_3_doubles matches RDB_MODULE_OPCODE_UINT (opcode 2) but TDigest's cap field is saved via RedisModule_SaveSigned, which writes with opcode SINT (value 1). Since SINT isn't defined or handled in this function, encountering it raises a RuntimeError("Unknown module opcode 1 ...") before patching occurs. The error message on line 226 ("Did not find target SINT to patch") confirms the intent was to target a signed field. The test_restore_rejects_corrupted_tdigest_cap test will always fail at the utility level.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 72aa2da. Configure here.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ 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 8e9fd3c. Configure here.
Avoid signed overflow when validating merged and unmerged node counts by widening the addition.
|
* 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. * 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. * MOD-13409 Share RDB corruption test helpers * Bump version to 8.9.91 * Fix TDigest RDB load node count overflow check Avoid signed overflow when validating merged and unmerged node counts by widening the addition.





Summary
Backport of #1038 to 8.10.
Testing
Note
Medium Risk
Changes deserialization of persisted module data on RESTORE/RDB load; incorrect bounds could reject valid snapshots, but scope is validation-only with targeted tests.
Overview
Hardens RESTORE/RDB load paths so crafted or mismatched serialized data is rejected before unsafe use, with regression tests that corrupt
DUMPpayloads and assert failedRESTORE.Bloom (
BFRdbLoad): After loading the bitset buffer, rejects null/empty buffers and absurd sizes; for newer encodings requiresbits == bytes*8, boundsn2, and consistency withbloom_validate_integrity. Legacy encodings keep the minimum-byte check only.Cuckoo (
CFRdbLoad): ValidatesnumFilters/numBucketsand uint16 fields against max limits, runsCuckooFilter_ValidateIntegritybefore allocating sub-filters, and replacesassertwith explicit checks that each sub-filter blob length matchesbucketSize * numBuckets(power-of-two buckets, overflow-safe multiply).TDigest (
TDigestRdbLoad): Fails on allocation failure; loadedcapmust be in(0, INT_MAX]and match the cap fromtd_new(compression); merged/unmerged node counts must be non-negative, within cap, and sum within cap.Shared
rdb_corruption_utils.pycentralizes DUMP parsing/CRC rewriting; Bloom/TopK tests import it and new cases cover shrunk Bloom/CF bit buffers, inflatednfilters, and inflated TDigestcap. Patch version 8.9.91.Reviewed by Cursor Bugbot for commit 669b0f1. Bugbot is set up for automated code reviews on this repo. Configure here.