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

Fixed SEGV when users pass nil messages. This also disallows nil in RepeatedField or Map. #8363

Merged
merged 2 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -326,18 +326,6 @@ def test_collect!
end
end

def test_compact!
m = TestMessage.new
m.repeated_msg << TestMessage2.new(:foo => 1)
m.repeated_msg << nil
m.repeated_msg << TestMessage2.new(:foo => 2)
reference_arr = m.repeated_string.to_a

check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
arr.compact!
end
end

def test_delete
m = TestMessage.new
reference_arr = %w(foo bar baz)
Expand Down
4 changes: 3 additions & 1 deletion ruby/ext/google/protobuf_c/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,9 @@ upb_msg* Message_deep_copy(const upb_msg* msg, const upb_msgdef* m,

const upb_msg* Message_GetUpbMessage(VALUE value, const upb_msgdef* m,
const char* name, upb_arena* arena) {
if (value == Qnil) return NULL;
if (value == Qnil) {
rb_raise(cTypeError, "nil message not allowed here.");
}

VALUE klass = CLASS_OF(value);
VALUE desc_rb = rb_ivar_get(klass, descriptor_instancevar_interned);
Expand Down
11 changes: 8 additions & 3 deletions ruby/tests/basic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,15 @@ def test_issue_8311_crash

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

outer_proto = outer.new(
outer.new(
inners: []
)
outer_proto['inners'].to_s
)['inners'].to_s

assert_raise Google::Protobuf::TypeError do
outer.new(
inners: [nil]
).to_s
end
end

def test_has_field
Expand Down
12 changes: 0 additions & 12 deletions ruby/tests/repeated_field_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -339,18 +339,6 @@ def test_collect!
end
end

def test_compact!
m = TestMessage.new
m.repeated_msg << TestMessage2.new(:foo => 1)
m.repeated_msg << nil
m.repeated_msg << TestMessage2.new(:foo => 2)
reference_arr = m.repeated_string.to_a

check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
arr.compact!
end
end

def test_delete
m = TestMessage.new
reference_arr = %w(foo bar baz)
Expand Down