diff --git a/upb/message/copy.c b/upb/message/copy.c index e9c5f6121a..32d71beeae 100644 --- a/upb/message/copy.c +++ b/upb/message/copy.c @@ -286,7 +286,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, while (upb_Message_NextUnknown(src, &unknowns, &iter)) { // Make a copy into destination arena. if (!UPB_PRIVATE(_upb_Message_AddUnknown)(dst, unknowns.data, unknowns.size, - arena)) { + arena, false)) { return NULL; } } diff --git a/upb/message/copy_test.cc b/upb/message/copy_test.cc index af0c4a96b1..d6fe9aa3a2 100644 --- a/upb/message/copy_test.cc +++ b/upb/message/copy_test.cc @@ -314,7 +314,7 @@ TEST(GeneratedCode, DeepCloneMessageWithUnknowns) { std::string unknown_data(data, len); // Add unknown data. UPB_PRIVATE(_upb_Message_AddUnknown) - (UPB_UPCAST(msg), data, len, source_arena); + (UPB_UPCAST(msg), data, len, source_arena, false); // Create clone. upb_Arena* clone_arena = upb_Arena_New(); protobuf_test_messages_proto2_TestAllTypesProto2* clone = diff --git a/upb/message/internal/compare_unknown_test.cc b/upb/message/internal/compare_unknown_test.cc index d655f66ee9..2d8c32cfa4 100644 --- a/upb/message/internal/compare_unknown_test.cc +++ b/upb/message/internal/compare_unknown_test.cc @@ -116,9 +116,9 @@ upb_UnknownCompareResult CompareUnknownWithMaxDepth(UnknownFields uf1, std::string buf1 = ToBinaryPayload(uf1); std::string buf2 = ToBinaryPayload(uf2); UPB_PRIVATE(_upb_Message_AddUnknown)(UPB_UPCAST(msg1), buf1.data(), - buf1.size(), arena1.ptr()); + buf1.size(), arena1.ptr(), false); UPB_PRIVATE(_upb_Message_AddUnknown)(UPB_UPCAST(msg2), buf2.data(), - buf2.size(), arena2.ptr()); + buf2.size(), arena2.ptr(), false); return UPB_PRIVATE(_upb_Message_UnknownFieldsAreEqual)( UPB_UPCAST(msg1), UPB_UPCAST(msg2), max_depth); } diff --git a/upb/message/internal/message.h b/upb/message/internal/message.h index 8f1b09bc47..2f7f0fae40 100644 --- a/upb/message/internal/message.h +++ b/upb/message/internal/message.h @@ -88,7 +88,7 @@ void _upb_Message_DiscardUnknown_shallow(struct upb_Message* msg); // The data is copied into the message instance. bool UPB_PRIVATE(_upb_Message_AddUnknown)(struct upb_Message* msg, const char* data, size_t len, - upb_Arena* arena); + upb_Arena* arena, bool alias); // Adds unknown data (serialized protobuf data) to the given message. // The data is copied into the message instance. Data when concatenated together diff --git a/upb/message/message.c b/upb/message/message.c index b4ce505f5d..6ac57887dd 100644 --- a/upb/message/message.c +++ b/upb/message/message.c @@ -37,7 +37,8 @@ upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* a) { } bool UPB_PRIVATE(_upb_Message_AddUnknown)(upb_Message* msg, const char* data, - size_t len, upb_Arena* arena) { + size_t len, upb_Arena* arena, + bool alias) { UPB_ASSERT(!upb_Message_IsFrozen(msg)); // TODO: b/376969853 - Add debug check that the unknown field is an overall // valid proto field diff --git a/upb/wire/decode.c b/upb/wire/decode.c index 4818b7ddc0..55e62ebea5 100644 --- a/upb/wire/decode.c +++ b/upb/wire/decode.c @@ -402,7 +402,7 @@ bool _upb_Decoder_CheckEnum(upb_Decoder* d, const char* ptr, upb_Message* msg, end = upb_Decoder_EncodeVarint32(v, end); if (!UPB_PRIVATE(_upb_Message_AddUnknown)(unknown_msg, buf, end - buf, - &d->arena)) { + &d->arena, false)) { _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); } return false; @@ -1265,8 +1265,9 @@ static const char* _upb_Decoder_DecodeUnknownField(upb_Decoder* d, // bounds checks are needed before adding the unknown field. _upb_Decoder_IsDone(d, &ptr); const char* input_ptr = upb_EpsCopyInputStream_GetInputPtr(&d->input, ptr); - if (!UPB_PRIVATE(_upb_Message_AddUnknown)( - msg, input_start, input_ptr - input_start, &d->arena)) { + if (!UPB_PRIVATE(_upb_Message_AddUnknown)(msg, input_start, + input_ptr - input_start, + &d->arena, d->input.aliasing)) { _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); } } else if (wire_type == kUpb_WireType_StartGroup) {