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

SEGV in Ruby when initializing with nil #8359

Closed
haberman opened this issue Mar 1, 2021 · 2 comments · Fixed by #8363
Closed

SEGV in Ruby when initializing with nil #8359

haberman opened this issue Mar 1, 2021 · 2 comments · Fixed by #8363

Comments

@haberman
Copy link
Member

haberman commented Mar 1, 2021

Per @tmtrademarked on #8311 (filing here as it is a different bug, needing a different fix):


After updating from 3.14.0 to 3.15.3, we started seeing a crash that appears related, even with the fix provided in the above PR. If the Inners field contains nil, you can still get a segfault. (In 3.14.0, this does not happen)

I've modified the repro script here slightly to demonstrate the failure mode:

require 'google/protobuf'

Google::Protobuf::DescriptorPool.generated_pool.build do
  add_file("inner.proto", :syntax => :proto3) do
    add_message "Inner" do
      # Removing either of these fixes the segfault.
      optional :foo, :string, 1
      optional :bar, :string, 2
    end
  end
end

Inner = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("Inner").msgclass

Google::Protobuf::DescriptorPool.generated_pool.build do
  add_file("outer.proto", :syntax => :proto3) do
    add_message "Outer" do
      repeated :inners, :message, 1, "Inner"
    end
  end
end

Outer = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("Outer").msgclass

outer_proto = Outer.new(
  inners: [nil]
)
puts outer_proto

With 3.14.0, I get the following output:

tom:branch (master *)$ bundle exec ruby --disable-did_you_mean ./repro.rb 
<Outer: inners: [nil]>

With 3.15.3, I get a segfault. I don't think that's quite what the intended behavior is, right?

@haberman
Copy link
Member Author

haberman commented Mar 1, 2021

Can you clarify, what behavior do you expect from this?

We generally don't allow nil elements in repeated fields. So I am inclined to have this use case raise an exception. Would that break your use case?

@tmtrademarked
Copy link

tmtrademarked commented Mar 1, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants