Poison initial Arena block with MSan.

We should always initialize it before we use it.

PiperOrigin-RevId: 693436567
pull/19101/head
Chris Kennelly 4 months ago committed by Copybara-Service
parent 21bec0fa3e
commit da08317d82
  1. 17
      csharp/src/Google.Protobuf/Reflection/FeatureSetDescriptor.g.cs
  2. 1
      src/google/protobuf/BUILD.bazel
  3. 5
      src/google/protobuf/arena.cc

@ -1,17 +0,0 @@
#region Copyright notice and license
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
#endregion
namespace Google.Protobuf.Reflection;
internal sealed partial class FeatureSetDescriptor
{
// Canonical serialized form of the edition defaults, generated by embed_edition_defaults.
private const string DefaultsBase64 =
"ChMYhAciACoMCAEQAhgCIAMoATACChMY5wciACoMCAIQARgBIAIoATABChMY6AciDAgBEAEYASACKAEwASoAIOYHKOgH";
}

@ -446,6 +446,7 @@ cc_library(
":string_block",
"//src/google/protobuf/stubs:lite",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/base:dynamic_annotations",
"@com_google_absl//absl/base:prefetch",
"@com_google_absl//absl/container:layout",
"@com_google_absl//absl/log:absl_check",

@ -16,6 +16,7 @@
#include <vector>
#include "absl/base/attributes.h"
#include "absl/base/dynamic_annotations.h"
#include "absl/base/prefetch.h"
#include "absl/container/internal/layout.h"
#include "absl/log/absl_check.h"
@ -584,6 +585,7 @@ ArenaBlock* ThreadSafeArena::FirstBlock(void* buf, size_t size) {
return SentryArenaBlock();
}
// Record user-owned block.
ABSL_ANNOTATE_MEMORY_IS_UNINITIALIZED(buf, size);
alloc_policy_.set_is_user_owned_initial_block(true);
return new (buf) ArenaBlock{nullptr, size};
}
@ -600,6 +602,7 @@ ArenaBlock* ThreadSafeArena::FirstBlock(void* buf, size_t size,
} else {
mem = {buf, size};
// Record user-owned block.
ABSL_ANNOTATE_MEMORY_IS_UNINITIALIZED(buf, size);
alloc_policy_.set_is_user_owned_initial_block(true);
}
@ -795,6 +798,8 @@ uint64_t ThreadSafeArena::Reset() {
size_t offset = alloc_policy_.get() == nullptr
? kBlockHeaderSize
: kBlockHeaderSize + kAllocPolicySize;
ABSL_ANNOTATE_MEMORY_IS_UNINITIALIZED(static_cast<char*>(mem.p) + offset,
mem.n - offset);
first_arena_.Init(new (mem.p) ArenaBlock{nullptr, mem.n}, offset);
} else {
first_arena_.Init(SentryArenaBlock(), 0);

Loading…
Cancel
Save