Commit d9668797 authored by Joshua Haberman's avatar Joshua Haberman Committed by Paul Yang

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.
parent be83f46b
...@@ -101,7 +101,7 @@ void DescriptorPool_mark(void* _self) { ...@@ -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) { ...@@ -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);
} }
......
...@@ -514,7 +514,7 @@ static void add_handlers_for_singular_field(upb_handlers *h, ...@@ -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, ...@@ -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) { ...@@ -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),
......
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -667,6 +667,13 @@ module BasicTest ...@@ -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},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment