-
Notifications
You must be signed in to change notification settings - Fork 1k
fix: json.set recursive processing crash #5040
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Please add explanation to the PR description. In general, for any non-trivial PRs, please state at least:
|
src/server/json_family_test.cc
Outdated
@@ -3087,4 +3087,29 @@ TEST_F(JsonFamilyTest, DepthLimitExceeded) { | |||
ASSERT_THAT(resp, ErrArg("ERR failed to parse JSON")); | |||
} | |||
|
|||
TEST_F(JsonFamilyTest, RecursiveDescentMutation) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once you identified the problem you should find what is the minimum possible unit test that can help reproducing the problem. It's fine to add tests here but it's necessary to add tests to src/core/json/jsonpath_test.cc
where you can reproduce it precisely and be able to iterate quickly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
4f9afa5
to
f1ade14
Compare
src/core/json/detail/jsoncons_dfs.h
Outdated
return depth_state_.first; | ||
} | ||
|
||
// Added getter for segment_step_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to write "added" in code comments :)
also, this comment is redundant we do not need describing c++ one liners.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
src/core/json/detail/jsoncons_dfs.cc
Outdated
@@ -8,6 +8,8 @@ | |||
|
|||
#include "core/json/detail/jsoncons_dfs.h" | |||
|
|||
#include <set> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we use #include <absl/container/flat_hash_set.h>
as drop in replacement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good work simplifying the fix!
f1ade14
to
71aa4c5
Compare
Fixes: #5038
What's not working:
Using JSON.SET with recursive descent paths ($..) on nested JSON objects could lead to hangs or crashes. This occurred because the mutation logic could process the same node multiple times if it was discovered via different paths during the traversal.
How this PR fixes the issue:
This PR adjusts the iteration logic. When processing elements of an object or array targeted by a path segment, the code now correctly handles iterator advancement, especially after an element might have been modified or erased by the mutation callback. This ensures that each element within the target object/array is considered for mutation exactly once during that step, preventing infinite loops or incorrect processing that previously led to the crash/hang with $.. paths.