Skip to content
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

identical() crashes when dealing with recursive fields in proto #56

jarodmeng opened this issue Nov 30, 2018 · 1 comment


None yet
2 participants
Copy link

commented Nov 30, 2018

Although it doesn't occur very often in the wild, it's possible to create protos that have recursive fields (see example proto below). When identical() is called to compare messages whose descriptor has recursive fields, R crashes due to stack overflow.

identical() calls C++ function identical_messages_() which iterates all fields in the messages' descriptor for a comprehensive comparison. In the case of recursive fields, this iteration never ends and eventually crashes.

One possible fix is for identical_messages_() to skip a field if it's not populated in both messages. This will naturally terminate the iteration at some point, because although a field's definition can be recursive, its actual data cannot be never-ending. I will send a PR for consideration.


# Create an example proto file with recursive field
proto.file <- tempfile(fileext = ".proto")
  syntax = 'proto2';

  package example;

  message Recursion {
      optional int32 id = 1;
      optional Recursion value = 2;
  ", proto.file

# Create two identical proto messages with recursive field unset
p <- new(example.Recursion, id = 1)
p2 <- new(example.Recursion, id = 1)

# R crashes when identical() is called
identical(p, p2)
all.equal(p, p2)

Created on 2018-11-30 by the reprex package (v0.2.1)


This comment has been minimized.

Copy link

commented Dec 1, 2018

Thanks for motivating a PR with an example. That is very good (yet rare ...) practice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.