Fixed data corruption when total hasbits are a power of two.

pull/13171/head
Joshua Haberman 3 years ago
parent 85e5c76cb7
commit 032400a03e
  1. 35
      tests/bindings/lua/test.proto
  2. 8
      tests/bindings/lua/test_upb.lua
  3. 2
      upb/def.c
  4. 2
      upbc/message_layout.cc

@ -32,3 +32,38 @@ message TestLargeFieldNumber {
message TestTimestamp {
optional google.protobuf.Timestamp ts = 1;
}
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;
}

@ -831,6 +831,14 @@ function test_gc()
end
end
function test_b9440()
local m = upb_test.HelloRequest()
m.id = 8
assert_equal(8, m.id)
m.version = "1"
assert_equal(8, m.id)
end
local stats = lunit.main()
if stats.failed > 0 or stats.errors > 0 then

@ -1574,7 +1574,7 @@ static void make_layout(symtab_addctx* ctx, const upb_MessageDef* m) {
}
/* Account for space used by hasbits. */
l->size = div_round_up(hasbit, 8);
l->size = hasbit ? div_round_up(hasbit + 1, 8) : 0;
/* Allocate non-oneof fields. */
for (int i = 0; i < m->field_count; i++) {

@ -190,7 +190,7 @@ void MessageLayout::PlaceNonOneofFields(
}
// Place hasbits at the beginning.
hasbit_bytes_ = DivRoundUp(hasbit_count_, 8);
hasbit_bytes_ = hasbit_count_ ? DivRoundUp(hasbit_count_ + 1, 8) : 0;
Place(SizeAndAlign{{hasbit_bytes_, hasbit_bytes_}, {1, 1}});
// Place non-oneof fields.

Loading…
Cancel
Save