Repository navigation
MOD-18588 - create new dedicated config fr checking depth in old rdbs - #1657
Conversation
5f43d23 to
0f65308
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high 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 0f65308. Configure here.
0f65308 to
fb039b7
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1657 +/- ##
==========================================
+ Coverage 88.13% 88.22% +0.09%
==========================================
Files 17 17
Lines 6049 6063 +14
==========================================
+ Hits 5331 5349 +18
+ Misses 718 714 -4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
c4aa023 to
e4f640a
Compare
| rdb: *mut raw::RedisModuleIO, | ||
| encver: c_int, | ||
| ) -> Option<RedisJSON<ijson::IValue>> { | ||
| let limit_depth = backward::legacy_rdb_depth_limit_enabled(); |
There was a problem hiding this comment.
Default no removes depth protection that master already has, so RESTORE can now crash the server.
On master, every RDB/RESTORE path was already bounded:
- encver 4:
ijson::decoderan ciborium's defaultfrom_reader(recursion limit 256) and thencbor_to_ivalue, which rejected atMAX_DEPTH. - encver 0/2/3:
from_str(..., true, ...)kept serde_json's 128 recursion limit.
With this PR and the setting at its default (no):
- encver 4 calls
decode_with_depth_limit(buf, false), which usesfrom_reader_with_recursion_limit(bytes, usize::MAX)and skips thecbor_to_ivaluecheck. Recursion is unbounded. - encver 0/2/3 call
from_str(..., false, ...), which runsdisable_recursion_limit()with noserde_stacker, so the parser recurses without bound.
Repro: RESTORE k 0 <encver-4 payload of ~1M nested CBOR 0x81 bytes> (about 1 MB), or an encver 3 payload holding [ repeated 1M times. Either one should overflow the stack and SIGSEGV the process. On master both return an error. testRestoreDepthLimitForAllEncodingVersions only uses depth 300, so it doesn't catch this, and its depth-off-* asserts lock in the weaker behaviour.
The PR summary and the module.conf comment say default compatibility is unchanged and that enabling the setting "protects" against stack exhaustion. In fact, the default disables a protection that already shipped. If the goal is to let old, deeply nested data load, a safer option when the setting is off is a much larger finite bound (for example a few thousand levels, or the stack-safe limit you measure) instead of usize::MAX / disable_recursion_limit(). The flag would then only choose between the strict 128 limit and that larger limit.
There was a problem hiding this comment.
This behavior is intentional. The 128-level depth limit for encver 2/3 was introduced unintentionally alongside the JSON.SET depth limit; it was not intended to apply to legacy RDB loading.
Keeping a mandatory limit for encver 4 would create a compatibility problem: a deeply nested document loaded from encver 0/2/3 is subsequently saved as encver 4. If encver 4 enforces the limit independently of the configuration, the same document would fail to load after a restart or RESTORE.
Therefore, the configuration must apply consistently across all supported encoding versions: when enabled, all enforce the depth limit; when disabled, none enforce it.
@AvivDavid23 @gabsow do we all agree ?
|
|
||
| # Reject RDB JSON documents nested deeper than 128 levels. | ||
| # Enabling this protects RESTORE and RDB loading from stack exhaustion, but | ||
| # may reject deeply nested legacy data. yes/no, default: no |
There was a problem hiding this comment.
"May reject" understates what happens at startup. When this is yes, rdb_load returns NULL for an over-deep key. While Redis is loading the RDB at boot (or a replica is loading after full sync), a NULL from a module rdb_load is fatal: Redis logs a short-read/module load error and exits. It does not skip the key. So turning this on with a single deeply nested legacy document in the dataset leaves the server unable to start, and a replica unable to sync. Only RESTORE gets the per-command error that the tests check. Please spell this out in the doc, or handle the startup case differently.

Note
Medium Risk
Opt-in by default, but enabling it can block RDB startup, replica sync, or RESTORE on deep legacy snapshots; RDB load path behavior changes across all encoding versions when the flag is on.
Overview
Adds an opt-in module setting
json-legacy-rdb-depth-limit(default no) that caps JSON nesting at 128 while loading from RDB/RESTORE, to reduce stack-exhaustion risk from pathologically deep snapshots.When enabled, legacy encver 0 loads track depth in
json_rdb_load_innerand fail with the existing recursion-limit error; encvers 2–4 useijson::decode_with_depth_limit(and depth-limitedfrom_strfor text encodings) instead of unbounded decode.ijsonis bumped to a git rev that exposes that API.module.confdocuments that over-limit data errors on RESTORE and can fail startup or replica full sync (keys are not skipped). Pytests forge nested RESTORE payloads for encvers 0/2/3/4 to assert reject/accept behavior with the flag on vs off.Reviewed by Cursor Bugbot for commit bb3c682. Bugbot is set up for automated code reviews on this repo. Configure here.