Skip to content

Commit 40add3d

Browse files
limit max nesting
1 parent a1a45a6 commit 40add3d

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

dump.rdb

92 Bytes
Binary file not shown.

src/commands.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,14 @@ pub fn json_set<M: Manager>(manager: M, ctx: &Context, args: Vec<RedisString>) -
625625
let mut res = false;
626626
if update_info.len() == 1 {
627627
res = match update_info.pop().unwrap() {
628-
UpdateInfo::SUI(sui) => redis_key.set_value(sui.path, val)?,
629-
UpdateInfo::AUI(aui) => redis_key.dict_add(aui.path, &aui.key, val)?,
628+
UpdateInfo::SUI(sui) => {
629+
if sui.path.len() < 128 {
630+
redis_key.set_value(sui.path, val)?
631+
} else {
632+
return Err(RedisError::Str("recursion limit exceeded"))
633+
}
634+
},
635+
UpdateInfo::AUI(aui) => redis_key.dict_add(aui.path, &aui.key, val)?
630636
}
631637
} else {
632638
for ui in update_info {

tests/pytest/test.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1138,16 +1138,14 @@ def testNesting(env):
11381138
res = r.execute_command('JSON.GET', 'test', '$..__leaf')
11391139
r.assertEqual(res, '[42]')
11401140

1141-
# No overall max nesting level (can exceeded the single value max nesting level)
1141+
# Max nesting level of nested objects cannot exceed 128
11421142
doc = nest_object(depth, 5, "__deep_leaf", 420)
11431143
r.execute_command('JSON.SET', 'test', '$..__leaf', doc)
11441144
res = r.execute_command('JSON.GET', 'test', '$..__deep_leaf')
11451145
r.assertEqual(res, '[420]')
11461146

11471147
doc = nest_object(depth, 5, "__helms_deep_leaf", 42000)
1148-
r.execute_command('JSON.SET', 'test', '$..__deep_leaf', doc)
1149-
res = r.execute_command('JSON.GET', 'test', '$..__helms_deep_leaf')
1150-
r.assertEqual(res, '[42000]')
1148+
r.expect('JSON.SET', 'test', '$..__deep_leaf', doc).raiseError().contains("recursion limit exceeded")
11511149

11521150
# Max nesting level for a single JSON value cannot be exceeded
11531151
depth = 129

0 commit comments

Comments
 (0)