)]}'
{
  "commit": "71dfd4890e372a6d57413d9557a7a5b45914a95c",
  "tree": "5483842f4cd4e06ebffcb57beb6fe4028a4808d0",
  "parents": [
    "caecd798cefe6f77270207c633f5415832c12725"
  ],
  "author": {
    "name": "Kaya Emre Arikan",
    "email": "25618690+kemrec@users.noreply.github.com",
    "time": "Thu Nov 05 14:58:31 2026 -0800"
  },
  "committer": {
    "name": "Copybara-Service",
    "email": "copybara-worker@google.com",
    "time": "Thu Nov 05 15:01:59 2026 -0800"
  },
  "message": "Add oneof ownership check to Reflection oneof APIs to prevent OOB memory access (#30395)\n\n## Summary\n\n`Reflection::HasOneof()`, `Reflection::ClearOneof()` and `Reflection::GetOneofFieldDescriptor()` compute the oneof-case address from the caller-supplied descriptor\u0027s index (via the private `GetOneofCase()`/`MutableOneofCase()` helpers and `ReflectionSchema::GetOneofCaseOffset()`, `generated_message_reflection.h:163-168`):\n\n```cpp\nuint32_t GetOneofCaseOffset(const OneofDescriptor* oneof_descriptor) const {\n  return static_cast\u003cuint32_t\u003e(oneof_case_offset_) +\n         static_cast\u003cuint32_t\u003e(static_cast\u003csize_t\u003e(oneof_descriptor-\u003eindex()) *\n                               sizeof(uint32_t));\n}\n```\n\nNone of the three methods validates that the descriptor belongs to the message they are called on, so a oneof descriptor from a different message type with a larger oneof index addresses memory outside the target object\u0027s oneof-case array: an out-of-bounds 4-byte read, and — in `ClearOneof()`, when the stale value resolves to a pointer-typed member of the target (string/message) — a `delete` of a value read from the message\u0027s oneof union, followed by a 4-byte write of 0 at the same offset.\n\nThis is the oneof counterpart of the field-side check added to `SwapFieldsImpl` in #27289: every field-taking method validates `field-\u003econtaining_type() \u003d\u003d descriptor_` via `USAGE_CHECK_MESSAGE_TYPE`; there is no equivalent validation for oneof descriptors anywhere in the tree. (Private `GetOneofCase()`/`MutableOneofCase()` are additionally reached from field-based paths that are already checked.)\n\n## Root cause\n\n- `HasOneof()` — `generated_message_reflection.cc:3383` (real-oneof branch)\n- `ClearOneof()` — `:3403`; the destroy path (`delete *MutableRaw\u003cMessage*\u003e(...)`) at `:3439`\n- `GetOneofFieldDescriptor()` — `:3023`\n- offset computation — `ReflectionSchema::GetOneofCaseOffset()`, `generated_message_reflection.h:163-168`\n\n## Fix\n\nAdd a `USAGE_CHECK_ONEOF_MESSAGE_TYPE` guard mirroring `USAGE_CHECK_MESSAGE_TYPE`, reported through a oneof-specific reporter (`ReportReflectionUsageOneofError`; the existing reporter prints a `FieldDescriptor` name). The check runs at the top of all three public methods, fails fast in all build modes (it is not `NDEBUG`-gated, matching the field-side check), and is unreachable for the library\u0027s own internal callers, which always pass the message\u0027s own oneof descriptors.\n\n## Test plan\n\n- New death test `GeneratedMessageReflectionTest.OneofForeignDescriptorCheck` — passes a `unittest::TestOneof2` oneof descriptor to `unittest::TestAllTypes` reflection for all three APIs and expects the usage error.\n- Full `//src/google/protobuf:generated_message_reflection_unittest` suite passes.\n- Verified on an ASan build of the runtime: before the change, the three calls show `heap-buffer-overflow` on the oneof-case read and `ClearOneof()` a `heap-use-after-free`; after the change each call terminates with the usage error instead.\n\nCloses #30395\n\nCOPYBARA_INTEGRATE_REVIEW\u003dhttps://github.com/protocolbuffers/protobuf/pull/30395 from kemrec:add-oneof-ownership-check aadb8ce70479a642b7801a48447e0a91d165baf1\nPiperOrigin-RevId: 1015015987\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "30c8afb2c5dc1bf37e0e0ba5c3f3a4714995e7dc",
      "old_mode": 33188,
      "old_path": "src/google/protobuf/generated_message_reflection.cc",
      "new_id": "293cbcddd5cc841b2825fe2c14434d5188ee8f6d",
      "new_mode": 33188,
      "new_path": "src/google/protobuf/generated_message_reflection.cc"
    },
    {
      "type": "modify",
      "old_id": "f6c72eff389876875bc88cecd0a1e48d3dad3cab",
      "old_mode": 33188,
      "old_path": "src/google/protobuf/generated_message_reflection_unittest.cc",
      "new_id": "df82165467c1a642065c8459afedc7b6c421c1e9",
      "new_mode": 33188,
      "new_path": "src/google/protobuf/generated_message_reflection_unittest.cc"
    }
  ]
}
