浏览代码

Update upb, fixes some bugs (including a hash table problem). (#2611)

* Update upb, fixes some bugs (including a hash table problem).

* Ruby: added a test for the previous hash table corruption.

Verified that this triggers the bug in the currently released
version.

* Ruby: bugfix for SEGV.

* Ruby: removed old code for dup'ing defs.
Joshua Haberman 8 年之前
父节点
当前提交
d9668797a2

+ 2 - 2
ruby/ext/google/protobuf_c/defs.c

@@ -101,7 +101,7 @@ void DescriptorPool_mark(void* _self) {
 
 
 void DescriptorPool_free(void* _self) {
 void DescriptorPool_free(void* _self) {
   DescriptorPool* self = _self;
   DescriptorPool* self = _self;
-  upb_symtab_unref(self->symtab, &self->symtab);
+  upb_symtab_free(self->symtab);
   xfree(self);
   xfree(self);
 }
 }
 
 
@@ -113,7 +113,7 @@ void DescriptorPool_free(void* _self) {
  */
  */
 VALUE DescriptorPool_alloc(VALUE klass) {
 VALUE DescriptorPool_alloc(VALUE klass) {
   DescriptorPool* self = ALLOC(DescriptorPool);
   DescriptorPool* self = ALLOC(DescriptorPool);
-  self->symtab = upb_symtab_new(&self->symtab);
+  self->symtab = upb_symtab_new();
   return TypedData_Wrap_Struct(klass, &_DescriptorPool_type, self);
   return TypedData_Wrap_Struct(klass, &_DescriptorPool_type, self);
 }
 }
 
 

+ 4 - 4
ruby/ext/google/protobuf_c/encode_decode.c

@@ -514,7 +514,7 @@ static void add_handlers_for_singular_field(upb_handlers *h,
     case UPB_TYPE_INT64:
     case UPB_TYPE_INT64:
     case UPB_TYPE_UINT64:
     case UPB_TYPE_UINT64:
     case UPB_TYPE_DOUBLE:
     case UPB_TYPE_DOUBLE:
-      upb_shim_set(h, f, offset, -1);
+      upb_msg_setscalarhandler(h, f, offset, -1);
       break;
       break;
     case UPB_TYPE_STRING:
     case UPB_TYPE_STRING:
     case UPB_TYPE_BYTES: {
     case UPB_TYPE_BYTES: {
@@ -925,7 +925,7 @@ static void putmsg(VALUE msg, const Descriptor* desc,
 static upb_selector_t getsel(const upb_fielddef *f, upb_handlertype_t type) {
 static upb_selector_t getsel(const upb_fielddef *f, upb_handlertype_t type) {
   upb_selector_t ret;
   upb_selector_t ret;
   bool ok = upb_handlers_getselector(f, type, &ret);
   bool ok = upb_handlers_getselector(f, type, &ret);
-  UPB_ASSERT_VAR(ok, ok);
+  UPB_ASSERT(ok);
   return ret;
   return ret;
 }
 }
 
 
@@ -939,9 +939,9 @@ static void putstr(VALUE str, const upb_fielddef *f, upb_sink *sink) {
   // We should be guaranteed that the string has the correct encoding because
   // We should be guaranteed that the string has the correct encoding because
   // we ensured this at assignment time and then froze the string.
   // we ensured this at assignment time and then froze the string.
   if (upb_fielddef_type(f) == UPB_TYPE_STRING) {
   if (upb_fielddef_type(f) == UPB_TYPE_STRING) {
-    assert(rb_enc_from_index(ENCODING_GET(value)) == kRubyStringUtf8Encoding);
+    assert(rb_enc_from_index(ENCODING_GET(str)) == kRubyStringUtf8Encoding);
   } else {
   } else {
-    assert(rb_enc_from_index(ENCODING_GET(value)) == kRubyString8bitEncoding);
+    assert(rb_enc_from_index(ENCODING_GET(str)) == kRubyString8bitEncoding);
   }
   }
 
 
   upb_sink_startstr(sink, getsel(f, UPB_HANDLER_STARTSTR), RSTRING_LEN(str),
   upb_sink_startstr(sink, getsel(f, UPB_HANDLER_STARTSTR), RSTRING_LEN(str),

文件差异内容过多而无法显示
+ 2857 - 1782
ruby/ext/google/protobuf_c/upb.c


文件差异内容过多而无法显示
+ 621 - 337
ruby/ext/google/protobuf_c/upb.h


+ 7 - 0
ruby/tests/basic.rb

@@ -667,6 +667,13 @@ module BasicTest
       end
       end
     end
     end
 
 
+    def test_map_corruption
+      # This pattern led to a crash in a previous version of upb/protobuf.
+      m = MapMessage.new(map_string_int32: { "aaa" => 1 })
+      m.map_string_int32['podid'] = 2
+      m.map_string_int32['aaa'] = 3
+    end
+
     def test_map_encode_decode
     def test_map_encode_decode
       m = MapMessage.new(
       m = MapMessage.new(
         :map_string_int32 => {"a" => 1, "b" => 2},
         :map_string_int32 => {"a" => 1, "b" => 2},

部分文件因为文件数量过多而无法显示