Skip to content

Commit

Permalink
Fixed quadratic memory use in array append for PHP and Ruby.
Browse files Browse the repository at this point in the history
  • Loading branch information
haberman committed Mar 4, 2021
1 parent fd8aabf commit 9b5e357
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
3 changes: 1 addition & 2 deletions php/ext/google/protobuf/php-upb.c
Original file line number Diff line number Diff line change
Expand Up @@ -7047,10 +7047,9 @@ void upb_array_set(upb_array *arr, size_t i, upb_msgval val) {
}

bool upb_array_append(upb_array *arr, upb_msgval val, upb_arena *arena) {
if (!_upb_array_realloc(arr, arr->len + 1, arena)) {
if (!upb_array_resize(arr, arr->len + 1, arena)) {
return false;
}
arr->len++;
upb_array_set(arr, arr->len - 1, val);
return true;
}
Expand Down
3 changes: 1 addition & 2 deletions ruby/ext/google/protobuf_c/ruby-upb.c
Original file line number Diff line number Diff line change
Expand Up @@ -6663,10 +6663,9 @@ void upb_array_set(upb_array *arr, size_t i, upb_msgval val) {
}

bool upb_array_append(upb_array *arr, upb_msgval val, upb_arena *arena) {
if (!_upb_array_realloc(arr, arr->len + 1, arena)) {
if (!upb_array_resize(arr, arr->len + 1, arena)) {
return false;
}
arr->len++;
upb_array_set(arr, arr->len - 1, val);
return true;
}
Expand Down

0 comments on commit 9b5e357

Please sign in to comment.