Skip to content

Commit

Permalink
Merge pull request #9451 from haberman/ruby-dataloss-bugfix
Browse files Browse the repository at this point in the history
Fixed data loss bug in Ruby extension
  • Loading branch information
haberman authored Jan 28, 2022
2 parents eb301e1 + 98b8e05 commit afeb6d8
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Python
* Make libprotobuf symbols local on OSX to fix issue #9395 (#9435)

Ruby
* Fixed a data loss bug that could occur when the number of `optional`
fields in a message is an exact multiple of 32. (#9440).

PHP
* Fixed a data loss bug that could occur when the number of `optional`
fields in a message is an exact multiple of 32. (#9440).
Expand Down
2 changes: 1 addition & 1 deletion ruby/ext/google/protobuf_c/ruby-upb.c
Original file line number Diff line number Diff line change
Expand Up @@ -5583,7 +5583,7 @@ static void make_layout(symtab_addctx *ctx, const upb_msgdef *m) {
}

/* Account for space used by hasbits. */
l->size = div_round_up(hasbit, 8);
l->size = div_round_up(hasbit + 1, 8);

/* Allocate non-oneof fields. */
for (upb_msg_field_begin(&it, m); !upb_msg_field_done(&it);
Expand Down
8 changes: 8 additions & 0 deletions ruby/tests/basic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ def test_issue_8559_crash
TestMessage.encode(msg)
end

def test_issue_9440
msg = HelloRequest.new
msg.id = 8
assert_equal 8, msg.id
msg.version = '1'
assert_equal 8, msg.id
end

def test_has_field
m = TestSingularFields.new
assert !m.has_singular_msg?
Expand Down
35 changes: 35 additions & 0 deletions ruby/tests/basic_test.proto
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,38 @@ message WithJsonName {
optional int32 foo_bar = 1 [json_name="jsonFooBar"];
repeated WithJsonName baz = 2 [json_name="jsonBaz"];
}

message HelloRequest {
optional uint32 id = 1;
optional uint32 random_name_a0 = 2;
optional uint32 random_name_a1 = 3;
optional uint32 random_name_a2 = 4;
optional uint32 random_name_a3 = 5;
optional uint32 random_name_a4 = 6;
optional uint32 random_name_a5 = 7;
optional uint32 random_name_a6 = 8;
optional uint32 random_name_a7 = 9;
optional uint32 random_name_a8 = 10;
optional uint32 random_name_a9 = 11;
optional uint32 random_name_b0 = 12;
optional uint32 random_name_b1 = 13;
optional uint32 random_name_b2 = 14;
optional uint32 random_name_b3 = 15;
optional uint32 random_name_b4 = 16;
optional uint32 random_name_b5 = 17;
optional uint32 random_name_b6 = 18;
optional uint32 random_name_b7 = 19;
optional uint32 random_name_b8 = 20;
optional uint32 random_name_b9 = 21;
optional uint32 random_name_c0 = 22;
optional uint32 random_name_c1 = 23;
optional uint32 random_name_c2 = 24;
optional uint32 random_name_c3 = 25;
optional uint32 random_name_c4 = 26;
optional uint32 random_name_c5 = 27;
optional uint32 random_name_c6 = 28;
optional uint32 random_name_c7 = 29;
optional uint32 random_name_c8 = 30;
optional uint32 random_name_c9 = 31;
optional string version = 32;
}

0 comments on commit afeb6d8

Please sign in to comment.