google-protobuf 4.35.0-x86_64-linux-gnu → 4.36.0.rc.1-x86_64-linux-gnu

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2472b6be23690c262df04abfe68594c4eb87503882dbde128a329b2cf920162a
4
- data.tar.gz: 6503bd5c5d3e1b9b45ffa35760ecbac01377af499cd02379ecc0340fe239a397
3
+ metadata.gz: 837b5eaed66ac9fa0c728fbaca7b85fe59c27ba5c2556f4da66217d4fb84df99
4
+ data.tar.gz: 14304fcf24a46ce0a2f6d6c36adf0dbcae547fa02d91ab19794fa8d1bb413112
5
5
  SHA512:
6
- metadata.gz: 63cd212e8f836a2ed31ed2bb50ae8a071116b8ac0acfe62d86df73a8d8a72f3e171e353fd0ec72c114e67f67993a18414859b818ec232c0457d64caf0a222f74
7
- data.tar.gz: 3deb43a6d45e77710bf6a0ec6f2f68f0c41c3c8993bfc2b381892f69fd214357813be9598370b1aa6f2bd705c4904192e67a87f36ab8903233bfeb0d6a62c21d
6
+ metadata.gz: 18374cad1085adecc1bd3aae498e4ff3f288a9950f1cd1f341944e49cc93168cac93f93c636a9a62d688b1e920c8b782f6a77ea9012c631d20618f8ebd72b6ff
7
+ data.tar.gz: '0824e34d1404279113615e1476504cabd44f0d52939c9a47764fad82d02ee8597ed17791ce498f5059f962c46c9b8ff20f83c011e03ef7cf47c1b8b58784a6ee'
@@ -112,8 +112,8 @@ VALUE Convert_CheckStringUtf8(VALUE str) {
112
112
  // not mean that it is *valid* UTF-8. We have to check separately
113
113
  // whether it is valid.
114
114
  if (rb_enc_str_coderange(str) == ENC_CODERANGE_BROKEN) {
115
- VALUE exc = rb_const_get_at(
116
- rb_cEncoding, rb_intern("InvalidByteSequenceError"));
115
+ VALUE exc =
116
+ rb_const_get_at(rb_cEncoding, rb_intern("InvalidByteSequenceError"));
117
117
  rb_raise(exc, "String is invalid UTF-8");
118
118
  }
119
119
  } else {
@@ -226,8 +226,8 @@ upb_MessageValue Convert_RubyToUpb(VALUE value, const char* name,
226
226
  }
227
227
  break;
228
228
  default:
229
- rb_raise(cTypeError,
230
- "Convert_RubyToUpb(): Unexpected type %d", (int)type_info.type);
229
+ rb_raise(cTypeError, "Convert_RubyToUpb(): Unexpected type %d",
230
+ (int)type_info.type);
231
231
  }
232
232
 
233
233
  return ret;
@@ -22,8 +22,8 @@
22
22
  // - If type is message and the Ruby value is a message instance, we will fuse
23
23
  // the message's arena into |arena|, to ensure that this message outlives the
24
24
  // container.
25
- upb_MessageValue Convert_RubyToUpb(VALUE ruby_val, const char *name,
26
- TypeInfo type_info, upb_Arena *arena);
25
+ upb_MessageValue Convert_RubyToUpb(VALUE ruby_val, const char* name,
26
+ TypeInfo type_info, upb_Arena* arena);
27
27
 
28
28
  // Converts |upb_val| to a Ruby VALUE according to |type_info|. This may involve
29
29
  // creating a Ruby wrapper object.
@@ -36,7 +36,7 @@ VALUE Convert_UpbToRuby(upb_MessageValue upb_val, TypeInfo type_info,
36
36
 
37
37
  // Creates a deep copy of |msgval| in |arena|.
38
38
  upb_MessageValue Msgval_DeepCopy(upb_MessageValue msgval, TypeInfo type_info,
39
- upb_Arena *arena);
39
+ upb_Arena* arena);
40
40
 
41
41
  // Returns true if |val1| and |val2| are equal. Their type is given by
42
42
  // |type_info|.
@@ -17,21 +17,21 @@ VALUE Map_EmptyFrozen(const upb_FieldDef* f);
17
17
 
18
18
  // Returns a Ruby wrapper object for the given map, which will be created if
19
19
  // one does not exist already.
20
- VALUE Map_GetRubyWrapper(const upb_Map *map, upb_CType key_type,
20
+ VALUE Map_GetRubyWrapper(const upb_Map* map, upb_CType key_type,
21
21
  TypeInfo value_type, VALUE arena);
22
22
 
23
23
  // Gets the underlying upb_Map for this Ruby map object, which must have
24
24
  // key/value type that match |field|. If this is not a map or the type doesn't
25
25
  // match, raises an exception.
26
- const upb_Map *Map_GetUpbMap(VALUE val, const upb_FieldDef *field,
27
- upb_Arena *arena);
26
+ const upb_Map* Map_GetUpbMap(VALUE val, const upb_FieldDef* field,
27
+ upb_Arena* arena);
28
28
 
29
29
  // Implements #inspect for this map by appending its contents to |b|.
30
- void Map_Inspect(StringBuilder *b, const upb_Map *map, upb_CType key_type,
30
+ void Map_Inspect(StringBuilder* b, const upb_Map* map, upb_CType key_type,
31
31
  TypeInfo val_type);
32
32
 
33
33
  // Returns a new Hash object containing the contents of this Map.
34
- VALUE Map_CreateHash(const upb_Map *map, upb_CType key_type, TypeInfo val_info);
34
+ VALUE Map_CreateHash(const upb_Map* map, upb_CType key_type, TypeInfo val_info);
35
35
 
36
36
  // Returns a deep copy of this Map object.
37
37
  VALUE Map_deep_copy(VALUE obj);
@@ -401,6 +401,9 @@ static VALUE Message_field_accessor(VALUE _self, const upb_FieldDef* f,
401
401
  if (upb_FieldDef_IsRepeated(f)) {
402
402
  // Map repeated fields to a new type with ints
403
403
  VALUE arr = rb_ary_new();
404
+ if (msgval.array_val == NULL) {
405
+ return arr;
406
+ }
404
407
  size_t i, n = upb_Array_Size(msgval.array_val);
405
408
  for (i = 0; i < n; i++) {
406
409
  upb_MessageValue elem = upb_Array_Get(msgval.array_val, i);
@@ -690,7 +693,10 @@ static VALUE Message_dup(VALUE _self) {
690
693
  VALUE new_msg = rb_class_new_instance(0, NULL, CLASS_OF(_self));
691
694
  Message* new_msg_self = ruby_to_Message(new_msg);
692
695
  const upb_MiniTable* m = upb_MessageDef_MiniTable(self->msgdef);
693
- upb_Message_ShallowCopy((upb_Message*)new_msg_self->msg, self->msg, m);
696
+ if (!upb_Message_ShallowCopy((upb_Message*)new_msg_self->msg, self->msg, m,
697
+ Arena_get(new_msg_self->arena))) {
698
+ rb_raise(rb_eRuntimeError, "Failed to shallow copy message.");
699
+ }
694
700
  Arena_fuse(self->arena, Arena_get(new_msg_self->arena));
695
701
  return new_msg;
696
702
  }
@@ -1052,8 +1058,8 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) {
1052
1058
  const upb_DefPool* pool = upb_FileDef_Pool(upb_MessageDef_File(msg->msgdef));
1053
1059
 
1054
1060
  int result = upb_JsonDecodeDetectingNonconformance(
1055
- RSTRING_PTR(data), RSTRING_LEN(data), (upb_Message*)msg->msg,
1056
- msg->msgdef, pool, options, Arena_get(msg->arena), &status);
1061
+ RSTRING_PTR(data), RSTRING_LEN(data), (upb_Message*)msg->msg, msg->msgdef,
1062
+ pool, options, Arena_get(msg->arena), &status);
1057
1063
 
1058
1064
  switch (result) {
1059
1065
  case kUpb_JsonDecodeResult_Ok:
@@ -15,13 +15,13 @@
15
15
  VALUE cParseError;
16
16
  VALUE cTypeError;
17
17
 
18
- const upb_FieldDef *map_field_key(const upb_FieldDef *field) {
19
- const upb_MessageDef *entry = upb_FieldDef_MessageSubDef(field);
18
+ const upb_FieldDef* map_field_key(const upb_FieldDef* field) {
19
+ const upb_MessageDef* entry = upb_FieldDef_MessageSubDef(field);
20
20
  return upb_MessageDef_FindFieldByNumber(entry, 1);
21
21
  }
22
22
 
23
- const upb_FieldDef *map_field_value(const upb_FieldDef *field) {
24
- const upb_MessageDef *entry = upb_FieldDef_MessageSubDef(field);
23
+ const upb_FieldDef* map_field_value(const upb_FieldDef* field) {
24
+ const upb_MessageDef* entry = upb_FieldDef_MessageSubDef(field);
25
25
  return upb_MessageDef_FindFieldByNumber(entry, 2);
26
26
  }
27
27
 
@@ -32,7 +32,7 @@ const upb_FieldDef *map_field_value(const upb_FieldDef *field) {
32
32
  struct StringBuilder {
33
33
  size_t size;
34
34
  size_t cap;
35
- char *data;
35
+ char* data;
36
36
  };
37
37
 
38
38
  typedef struct StringBuilder StringBuilder;
@@ -41,21 +41,21 @@ static size_t StringBuilder_SizeOf(size_t cap) {
41
41
  return sizeof(StringBuilder) + cap;
42
42
  }
43
43
 
44
- StringBuilder *StringBuilder_New() {
44
+ StringBuilder* StringBuilder_New() {
45
45
  const size_t cap = 128;
46
- StringBuilder *builder = malloc(sizeof(*builder));
46
+ StringBuilder* builder = malloc(sizeof(*builder));
47
47
  builder->size = 0;
48
48
  builder->cap = cap;
49
49
  builder->data = malloc(builder->cap);
50
50
  return builder;
51
51
  }
52
52
 
53
- void StringBuilder_Free(StringBuilder *b) {
53
+ void StringBuilder_Free(StringBuilder* b) {
54
54
  free(b->data);
55
55
  free(b);
56
56
  }
57
57
 
58
- void StringBuilder_Printf(StringBuilder *b, const char *fmt, ...) {
58
+ void StringBuilder_Printf(StringBuilder* b, const char* fmt, ...) {
59
59
  size_t have = b->cap - b->size;
60
60
  size_t n;
61
61
  va_list args;
@@ -79,15 +79,15 @@ void StringBuilder_Printf(StringBuilder *b, const char *fmt, ...) {
79
79
  b->size += n;
80
80
  }
81
81
 
82
- VALUE StringBuilder_ToRubyString(StringBuilder *b) {
82
+ VALUE StringBuilder_ToRubyString(StringBuilder* b) {
83
83
  VALUE ret = rb_str_new(b->data, b->size);
84
84
  rb_enc_associate(ret, rb_utf8_encoding());
85
85
  return ret;
86
86
  }
87
87
 
88
- static void StringBuilder_PrintEnum(StringBuilder *b, int32_t val,
89
- const upb_EnumDef *e) {
90
- const upb_EnumValueDef *ev = upb_EnumDef_FindValueByNumber(e, val);
88
+ static void StringBuilder_PrintEnum(StringBuilder* b, int32_t val,
89
+ const upb_EnumDef* e) {
90
+ const upb_EnumValueDef* ev = upb_EnumDef_FindValueByNumber(e, val);
91
91
  if (ev) {
92
92
  StringBuilder_Printf(b, ":%s", upb_EnumValueDef_Name(ev));
93
93
  } else {
@@ -95,7 +95,7 @@ static void StringBuilder_PrintEnum(StringBuilder *b, int32_t val,
95
95
  }
96
96
  }
97
97
 
98
- void StringBuilder_PrintMsgval(StringBuilder *b, upb_MessageValue val,
98
+ void StringBuilder_PrintMsgval(StringBuilder* b, upb_MessageValue val,
99
99
  TypeInfo info) {
100
100
  switch (info.type) {
101
101
  case kUpb_CType_Bool:
@@ -145,25 +145,25 @@ void StringBuilder_PrintMsgval(StringBuilder *b, upb_MessageValue val,
145
145
  // -----------------------------------------------------------------------------
146
146
 
147
147
  typedef struct {
148
- upb_Arena *arena;
148
+ upb_Arena* arena;
149
149
  // IMPORTANT: WB_PROTECTED objects must only use the RB_OBJ_WRITE()
150
150
  // macro to update VALUE references, as to trigger write barriers.
151
151
  VALUE pinned_objs;
152
152
  } Arena;
153
153
 
154
- static void Arena_mark(void *data) {
155
- Arena *arena = data;
154
+ static void Arena_mark(void* data) {
155
+ Arena* arena = data;
156
156
  rb_gc_mark(arena->pinned_objs);
157
157
  }
158
158
 
159
- static void Arena_free(void *data) {
160
- Arena *arena = data;
159
+ static void Arena_free(void* data) {
160
+ Arena* arena = data;
161
161
  upb_Arena_Free(arena->arena);
162
162
  xfree(arena);
163
163
  }
164
164
 
165
- static size_t Arena_memsize(const void *data) {
166
- const Arena *arena = data;
165
+ static size_t Arena_memsize(const void* data) {
166
+ const Arena* arena = data;
167
167
  size_t fused_count;
168
168
  size_t memsize = upb_Arena_SpaceAllocated(arena->arena, &fused_count);
169
169
  if (fused_count > 1) {
@@ -182,8 +182,8 @@ const rb_data_type_t Arena_type = {
182
182
  .flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
183
183
  };
184
184
 
185
- static void *ruby_upb_allocfunc(upb_alloc *alloc, void *ptr, size_t oldsize,
186
- size_t size, size_t *actual_size) {
185
+ static void* ruby_upb_allocfunc(upb_alloc* alloc, void* ptr, size_t oldsize,
186
+ size_t size, size_t* actual_size) {
187
187
  if (size == 0) {
188
188
  xfree(ptr);
189
189
  return NULL;
@@ -195,20 +195,20 @@ static void *ruby_upb_allocfunc(upb_alloc *alloc, void *ptr, size_t oldsize,
195
195
  upb_alloc ruby_upb_alloc = {&ruby_upb_allocfunc};
196
196
 
197
197
  static VALUE Arena_alloc(VALUE klass) {
198
- Arena *arena = ALLOC(Arena);
198
+ Arena* arena = ALLOC(Arena);
199
199
  arena->arena = upb_Arena_Init(NULL, 0, &ruby_upb_alloc);
200
200
  arena->pinned_objs = Qnil;
201
201
  return TypedData_Wrap_Struct(klass, &Arena_type, arena);
202
202
  }
203
203
 
204
- upb_Arena *Arena_get(VALUE _arena) {
205
- Arena *arena;
204
+ upb_Arena* Arena_get(VALUE _arena) {
205
+ Arena* arena;
206
206
  TypedData_Get_Struct(_arena, Arena, &Arena_type, arena);
207
207
  return arena->arena;
208
208
  }
209
209
 
210
- void Arena_fuse(VALUE _arena, upb_Arena *other) {
211
- Arena *arena;
210
+ void Arena_fuse(VALUE _arena, upb_Arena* other) {
211
+ Arena* arena;
212
212
  TypedData_Get_Struct(_arena, Arena, &Arena_type, arena);
213
213
  if (!upb_Arena_Fuse(arena->arena, other)) {
214
214
  rb_raise(rb_eRuntimeError,
@@ -255,7 +255,7 @@ static void ObjectCache_Init(VALUE protobuf) {
255
255
  rb_const_set(internal, rb_intern("SIZEOF_VALUE"), INT2NUM(SIZEOF_VALUE));
256
256
  }
257
257
 
258
- static VALUE ObjectCache_GetKey(const void *key) {
258
+ static VALUE ObjectCache_GetKey(const void* key) {
259
259
  VALUE key_val = (VALUE)key;
260
260
  PBRUBY_ASSERT((key_val & 3) == 0);
261
261
  // Ensure the key can be stored as a Fixnum since 1 bit is needed for
@@ -265,13 +265,13 @@ static VALUE ObjectCache_GetKey(const void *key) {
265
265
  return new_key;
266
266
  }
267
267
 
268
- VALUE ObjectCache_TryAdd(const void *key, VALUE val) {
268
+ VALUE ObjectCache_TryAdd(const void* key, VALUE val) {
269
269
  VALUE key_val = ObjectCache_GetKey(key);
270
270
  return rb_funcall(weak_obj_cache, item_try_add, 2, key_val, val);
271
271
  }
272
272
 
273
273
  // Returns the cached object for this key, if any. Otherwise returns Qnil.
274
- VALUE ObjectCache_Get(const void *key) {
274
+ VALUE ObjectCache_Get(const void* key) {
275
275
  VALUE key_val = ObjectCache_GetKey(key);
276
276
  return rb_funcall(weak_obj_cache, item_get, 1, key_val);
277
277
  }
@@ -284,8 +284,8 @@ VALUE ObjectCache_Get(const void *key) {
284
284
  * unknown fields in submessages.
285
285
  */
286
286
  static VALUE Google_Protobuf_discard_unknown(VALUE self, VALUE msg_rb) {
287
- const upb_MessageDef *m;
288
- upb_Message *msg = Message_GetMutable(msg_rb, &m);
287
+ const upb_MessageDef* m;
288
+ upb_Message* msg = Message_GetMutable(msg_rb, &m);
289
289
  const upb_DefPool* ext_pool = upb_FileDef_Pool(upb_MessageDef_File(m));
290
290
  if (!upb_Message_DiscardUnknown(msg, m, ext_pool, 128)) {
291
291
  rb_raise(rb_eRuntimeError, "Messages nested too deeply.");
@@ -309,10 +309,10 @@ VALUE Google_Protobuf_deep_copy(VALUE self, VALUE obj) {
309
309
  return Map_deep_copy(obj);
310
310
  } else {
311
311
  VALUE new_arena_rb = Arena_new();
312
- upb_Arena *new_arena = Arena_get(new_arena_rb);
313
- const upb_MessageDef *m;
314
- const upb_Message *msg = Message_Get(obj, &m);
315
- upb_Message *new_msg = Message_deep_copy(msg, m, new_arena);
312
+ upb_Arena* new_arena = Arena_get(new_arena_rb);
313
+ const upb_MessageDef* m;
314
+ const upb_Message* msg = Message_Get(obj, &m);
315
+ upb_Message* new_msg = Message_deep_copy(msg, m, new_arena);
316
316
  return Message_GetRubyWrapper(new_msg, m, new_arena_rb);
317
317
  }
318
318
  }
@@ -351,7 +351,7 @@ __attribute__((visibility("default"))) void Init_protobuf_c() {
351
351
 
352
352
  // Raises a Ruby error if val is frozen in Ruby or UPB.
353
353
  void Protobuf_CheckNotFrozen(VALUE val, bool upb_frozen) {
354
- if (RB_UNLIKELY(rb_obj_frozen_p(val)||upb_frozen)) {
354
+ if (RB_UNLIKELY(rb_obj_frozen_p(val) || upb_frozen)) {
355
355
  rb_error_frozen_object(val);
356
356
  }
357
357
  }
@@ -180,11 +180,18 @@ static int index_position(VALUE _index, RepeatedField* repeated_field) {
180
180
  }
181
181
 
182
182
  static VALUE RepeatedField_subarray(RepeatedField* self, long beg, long len) {
183
- size_t size = upb_Array_Size(self->array);
184
- VALUE ary = rb_ary_new2(size);
185
- long i;
186
-
187
- for (i = beg; i < beg + len; i++) {
183
+ long size = (long)upb_Array_Size(self->array);
184
+
185
+ // Match Ruby Array#[beg, len] semantics and avoid an out-of-bounds read
186
+ // through upb_Array_Get (which only has a debug-only UPB_ASSERT for
187
+ // bounds): clamp len to what is actually available, and reject negative
188
+ // len up front.
189
+ if (len < 0) return Qnil;
190
+ if (beg < 0 || beg > size) return Qnil;
191
+ if (len > size - beg) len = size - beg;
192
+
193
+ VALUE ary = rb_ary_new2(len);
194
+ for (long i = beg; i < beg + len; i++) {
188
195
  upb_MessageValue msgval = upb_Array_Get(self->array, i);
189
196
  VALUE elem = Convert_UpbToRuby(msgval, self->type_info, self->arena);
190
197
  rb_ary_push(ary, elem);
@@ -264,7 +271,7 @@ static VALUE RepeatedField_index(int argc, VALUE* argv, VALUE _self) {
264
271
  if (beg < 0) {
265
272
  beg += size;
266
273
  }
267
- if (beg >= size) {
274
+ if (beg > size) {
268
275
  return Qnil;
269
276
  }
270
277
  return RepeatedField_subarray(self, beg, len);