diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index b96d64f19b8d0..b40b76f7f298b 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -3921,7 +3921,7 @@ bool UPB_PRIVATE(_upb_Message_AddUnknown)(upb_Message* msg, const char* data, UPB_ASSERT(!upb_Message_IsFrozen(msg)); // TODO: b/376969853 - Add debug check that the unknown field is an overall // valid proto field - if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, len, arena)) return false; + if (!UPB_PRIVATE(_upb_Message_EnsureAvailable)(msg, len, arena)) return false; upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg); memcpy(UPB_PTR_AT(in, in->unknown_end, char), data, len); in->unknown_end += len; @@ -3938,7 +3938,8 @@ bool UPB_PRIVATE(_upb_Message_AddUnknownV)(struct upb_Message* msg, for (size_t i = 0; i < count; i++) { total_len += data[i].size; } - if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, total_len, arena)) return false; + if (!UPB_PRIVATE(_upb_Message_EnsureAvailable)(msg, total_len, arena)) + return false; upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg); for (size_t i = 0; i < count; i++) { @@ -12385,7 +12386,7 @@ upb_Extension* UPB_PRIVATE(_upb_Message_GetOrCreateExtension)( UPB_ASSERT(!upb_Message_IsFrozen(msg)); upb_Extension* ext = (upb_Extension*)UPB_PRIVATE(_upb_Message_Getext)(msg, e); if (ext) return ext; - if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(upb_Extension), a)) + if (!UPB_PRIVATE(_upb_Message_EnsureAvailable)(msg, sizeof(upb_Extension), a)) return NULL; upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg); in->ext_begin -= sizeof(upb_Extension); @@ -12426,8 +12427,8 @@ const double kUpb_Infinity = INFINITY; const double kUpb_NaN = UPB_NAN; -bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need, - upb_Arena* a) { +bool UPB_PRIVATE(_upb_Message_EnsureAvailable)(struct upb_Message* msg, + size_t need, upb_Arena* a) { UPB_ASSERT(!upb_Message_IsFrozen(msg)); const size_t overhead = sizeof(upb_Message_Internal); diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index aad02a6e30c0c..b0874336f1cd3 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -2608,8 +2608,11 @@ bool UPB_PRIVATE(_upb_Message_AddUnknownV)(struct upb_Message* msg, upb_Arena* arena, upb_StringView data[], size_t count); -bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need, - upb_Arena* arena); +// Ensure at least `need` unused bytes are available for unknown fields or +// extensions. Returns false if a reallocation is needed to satisfy the request, +// and fails. +bool UPB_PRIVATE(_upb_Message_EnsureAvailable)(struct upb_Message* msg, + size_t need, upb_Arena* arena); #define kUpb_Message_UnknownBegin 0 #define kUpb_Message_ExtensionBegin 0 diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index 6bae049a73503..266b14e93800f 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -3921,7 +3921,7 @@ bool UPB_PRIVATE(_upb_Message_AddUnknown)(upb_Message* msg, const char* data, UPB_ASSERT(!upb_Message_IsFrozen(msg)); // TODO: b/376969853 - Add debug check that the unknown field is an overall // valid proto field - if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, len, arena)) return false; + if (!UPB_PRIVATE(_upb_Message_EnsureAvailable)(msg, len, arena)) return false; upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg); memcpy(UPB_PTR_AT(in, in->unknown_end, char), data, len); in->unknown_end += len; @@ -3938,7 +3938,8 @@ bool UPB_PRIVATE(_upb_Message_AddUnknownV)(struct upb_Message* msg, for (size_t i = 0; i < count; i++) { total_len += data[i].size; } - if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, total_len, arena)) return false; + if (!UPB_PRIVATE(_upb_Message_EnsureAvailable)(msg, total_len, arena)) + return false; upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg); for (size_t i = 0; i < count; i++) { @@ -11872,7 +11873,7 @@ upb_Extension* UPB_PRIVATE(_upb_Message_GetOrCreateExtension)( UPB_ASSERT(!upb_Message_IsFrozen(msg)); upb_Extension* ext = (upb_Extension*)UPB_PRIVATE(_upb_Message_Getext)(msg, e); if (ext) return ext; - if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(upb_Extension), a)) + if (!UPB_PRIVATE(_upb_Message_EnsureAvailable)(msg, sizeof(upb_Extension), a)) return NULL; upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg); in->ext_begin -= sizeof(upb_Extension); @@ -11913,8 +11914,8 @@ const double kUpb_Infinity = INFINITY; const double kUpb_NaN = UPB_NAN; -bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need, - upb_Arena* a) { +bool UPB_PRIVATE(_upb_Message_EnsureAvailable)(struct upb_Message* msg, + size_t need, upb_Arena* a) { UPB_ASSERT(!upb_Message_IsFrozen(msg)); const size_t overhead = sizeof(upb_Message_Internal); diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index d0d4b25a6b50e..6593d47f7a2b0 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -2610,8 +2610,11 @@ bool UPB_PRIVATE(_upb_Message_AddUnknownV)(struct upb_Message* msg, upb_Arena* arena, upb_StringView data[], size_t count); -bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need, - upb_Arena* arena); +// Ensure at least `need` unused bytes are available for unknown fields or +// extensions. Returns false if a reallocation is needed to satisfy the request, +// and fails. +bool UPB_PRIVATE(_upb_Message_EnsureAvailable)(struct upb_Message* msg, + size_t need, upb_Arena* arena); #define kUpb_Message_UnknownBegin 0 #define kUpb_Message_ExtensionBegin 0