-
Notifications
You must be signed in to change notification settings - Fork 15.6k
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
[Ruby] Message.decode/encode: Add max_recursion_depth option #9218
[Ruby] Message.decode/encode: Add max_recursion_depth option #9218
Conversation
Depends on protocolbuffers/protobuf#9218, until that is merged this can only be used with a custom built protobuf gem. Fixes #209
Depends on protocolbuffers/protobuf#9218, until that is merged this can only be used with a custom built protobuf gem. Fixes #209
Depends on protocolbuffers/protobuf#9218, until that is merged this can only be used with a custom built protobuf gem. Fixes #209
c1d3b1b
to
fab7498
Compare
ruby/ext/google/protobuf_c/message.c
Outdated
VALUE depth = rb_hash_lookup(hash_args, ID2SYM(rb_intern("max_recursion_depth"))); | ||
|
||
if (depth != Qnil && TYPE(depth) == T_FIXNUM) { | ||
options = FIX2INT(depth) << 16; |
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.
Please use UPB_DECODE_MAXDEPTH()
. And we should also avoid overwriting the options completely, eg.
options |= UPB_DECODE_MAXDEPTH(FIX2INT(depth));
ruby/ext/google/protobuf_c/message.c
Outdated
VALUE depth = rb_hash_lookup(hash_args, ID2SYM(rb_intern("max_recursion_depth"))); | ||
|
||
if (depth != Qnil && TYPE(depth) == T_FIXNUM) { | ||
options = FIX2INT(depth) << 16; |
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.
Ditto here.
Looks like we need this implemented on the JRuby side too. |
@haberman Thanks for the review - addressed in the latest commit. |
protected DynamicMessage build(ThreadContext context, int depth) { | ||
if (depth > SINK_MAXIMUM_NESTING) { | ||
protected DynamicMessage build(ThreadContext context, int depth, int maxRecursionDepth) { | ||
if (depth >= maxRecursionDepth) { |
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.
Note this is changed to match the UPB library behavior (>
=> >=
), and SINK_MAXIMUM_NESTING is incremented by one accordingly.
@haberman I wanted to check if you could re-trigger a test build so we can confirm that the issues are now fixed? Thanks! |
This allows increasing the recursing depth from the default of 64, by setting the "max_recursion_depth" to the desired integer value. This is useful to encode or decode complex nested protobuf messages that otherwise error out with a RuntimeError or "Error occurred during parsing". Fixes protocolbuffers#1493
51433c5
to
29909eb
Compare
@acozzette Thanks for the re-run - I can't really explain the test failure, it does not seem related to the actual code change. I've just rebased onto the latest Could you re-run once more? Thank you! |
@lfittl I noticed that some of our Ruby tests started failing a few days ago, though I have not had a chance to investigate yet. It could well be that the test failure is unrelated. |
Yeah, looks like the release tests are still failing (as they are on #9291), but otherwise this is green now (looks like the rebase fixed the other tests). @haberman Let me know if you'd like to see any other adjustments. Thanks for reviewing! |
@haberman Happy New Year! - let me know if you'd like to see anything else adjusted on this PR :) |
I tried to resolve the merge conflicts in the GitHub UI just now. Hopefully that will work and then I will merge this unless @haberman has other comments. |
I think the only remaining issue is making sure we are being as consistent as possible with other languages: I just checked and Java, C++, and appears to calls this "recursion limit" instead of "max recursion depth: protobuf/csharp/src/Google.Protobuf/CodedInputStream.cs Lines 231 to 241 in 3f5fc4d
protobuf/src/google/protobuf/io/coded_stream.h Lines 418 to 419 in 3e1967e
protobuf/java/core/src/main/java/com/google/protobuf/CodedInputStream.java Lines 386 to 400 in d8ccfbf
In that case, could we call the parameter Sorry for the delay! |
Let me go ahead and merge this, and I will send out a follow-up pull request to rename the parameter to |
@acozzette @haberman Excellent, thanks for the help & merging this :) |
This allows increasing the recursing depth from the default of 64, by
setting the "max_recursion_depth" to the desired integer value. This is
useful to encode or decode complex nested protobuf messages that otherwise
error out with a RuntimeError or "Error occurred during parsing".
Fixes #1493