dep-protobuf/objectivec/Tests
Tony Liao dd9d2ad02d [ObjC] Carry recursion depth across MessageSet item parsing (#27571)
## Summary

`GPBMessage::parseMessageSet:` reads each MessageSet item's payload bytes into
a separate buffer (because the type-id and payload tags can appear in any
order), then allocates a fresh `GPBCodedInputStream` to decode that buffer. The
fresh stream's `state_.recursionDepth` starts at `0` even when the parent
stream is already several MessageSet items deep, so a chain of nested
MessageSet items grows the native call stack without ever tripping the
documented `kDefaultRecursionLimit` (100). Other parser entry points that
recurse on the same stream (`readGroup:`, `readMessage:`, `readMapEntry:`,
`SkipToEndGroupInternal`) already increment and check `recursionDepth`; the
MessageSet path was the only spot where depth tracking did not cross the stream
boundary.

This change adds a package-private `-initWithData:parentRecursionDepth:`
initializer to `GPBCodedInputStream` that seeds the child stream's depth from
the parent's and runs `CheckRecursionLimit` before parsing begins. To prevent
memory leaks if `CheckRecursionLimit` raises an exception during
initialization, the check is wrapped in a `@try/@catch` block that releases
`self`. `parseMessageSet:` uses that initializer, so depth tracking carries
across the fresh stream. This mirrors the depth-inheritance done by the C++
`ParseContext` spawn helper.

Regression coverage: `testParseMessageSetRecursionDepthCarriedFromParent` in
`GPBWireFormatTests` builds MessageSet-of-MessageSet payloads (each layer is
`MSetMessage -> MSetMessageExtension1.recursive -> MSetMessage -> ...`, adding
2 to the recursion depth per layer). It verifies that 50 layers (depth 100,
`kDefaultRecursionLimit`) parses successfully, while 51 layers (depth 101,
`kDefaultRecursionLimit + 1`) fails with
`GPBCodedInputStreamErrorRecursionDepthExceeded`. Existing
`testErrorRecursionDepthReached` and the rest of `GPBWireFormatTests` continue
to pass unchanged.

## Test plan

- Existing ObjC test suite passes (`GPBWireFormatTests`,
  `GPBMessageTests+Serialization`, `GPBCodedInputStreamTests`,
  `GPBUnknownFieldsTest`).
- New `testParseMessageSetRecursionDepthCarriedFromParent` passes for both 50
  layers (passing at kDefaultRecursionLimit) and 51 layers (failing at
  kDefaultRecursionLimit + 1).

Closes #27571

PiperOrigin-RevId: 959041690
2026-08-04 08:41:24 -07:00
..
any_test.proto Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
expected_prefixes.txt [ObjC] Test file cleanups 2022-08-30 10:46:17 -04:00
golden_message Alpha 1 drop of Google's Objective C plugin and runtime support for protobufs. 2015-05-06 13:19:14 -04:00
golden_packed_fields_message Alpha 1 drop of Google's Objective C plugin and runtime support for protobufs. 2015-05-06 13:19:14 -04:00
GPBARCUnittestProtos.m Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
GPBArrayTests.m [ObjC] Use more complete imports 2024-09-05 08:52:31 -07:00
GPBCodedInputStreamTests.m [ObjC] Breaking Change: Remove GPBUnknownFieldSet. 2024-10-09 16:14:56 -07:00
GPBCodedOutputStreamTests.m [ObjC] Fix some tests to not violate GPBCodedOutputStream invariants. 2025-10-09 06:17:35 -07:00
GPBCompileTest01.m Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
GPBCompileTest02.m Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
GPBCompileTest03.m Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
GPBCompileTest04.m Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
GPBCompileTest05.m Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
GPBCompileTest06.m Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
GPBCompileTest07.m Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
GPBCompileTest08.m Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
GPBCompileTest09.m Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
GPBCompileTest10.m [ObjC] Breaking Change: Remove GPBUnknownFieldSet. 2024-10-09 16:14:56 -07:00
GPBCompileTest11.m Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
GPBCompileTest12.m Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
GPBCompileTest13.m Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
GPBCompileTest14.m Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
GPBCompileTest15.m Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
GPBCompileTest16.m Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
GPBCompileTest17.m Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
GPBCompileTest18.m Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
GPBCompileTest19.m Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
GPBCompileTest20.m Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
GPBCompileTest21.m Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
GPBCompileTest22.m Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
GPBCompileTest23.m Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
GPBCompileTest24.m [ObjC] Fix issue using GPBBootstrap.h only. 2024-02-26 07:37:41 -08:00
GPBConcurrencyTests.m Modify unit tests to use c_function extension syntax via ifdefs 2026-02-26 17:51:54 -08:00
GPBDescriptorTests.m Use XCTAssertEqualObjects to compare enum values with NSNumbers in the GPBDescriptorTests. 2026-06-15 06:55:05 -07:00
GPBDictionaryTests+Bool.m [ObjC] Use more complete imports 2024-09-05 08:52:31 -07:00
GPBDictionaryTests+Int32.m [ObjC] Use more complete imports 2024-09-05 08:52:31 -07:00
GPBDictionaryTests+Int64.m [ObjC] Use more complete imports 2024-09-05 08:52:31 -07:00
GPBDictionaryTests+String.m [ObjC] Use more complete imports 2024-09-05 08:52:31 -07:00
GPBDictionaryTests+UInt32.m [ObjC] Use more complete imports 2024-09-05 08:52:31 -07:00
GPBDictionaryTests+UInt64.m [ObjC] Use more complete imports 2024-09-05 08:52:31 -07:00
GPBDictionaryTests.m [ObjC] Use more complete imports 2024-09-05 08:52:31 -07:00
GPBDictionaryTests.pddm Internal change 2023-09-18 15:17:56 -07:00
GPBExtensionRegistryTest.m Modify unit tests to use c_function extension syntax via ifdefs 2026-02-26 17:51:54 -08:00
GPBMessage30007FormatTest.m [ObjC] Deprecate GPBFieldDescriptor.isOptional. 2025-03-25 09:38:38 -07:00
GPBMessage40310FormatTest.m [ObjC] Deprecate GPBFieldDescriptor.isOptional. 2025-03-25 09:38:38 -07:00
GPBMessage40311FormatTest.m [ObjC] Add a new compile test for the new generated code format. 2025-03-26 11:00:08 -07:00
GPBMessageBadVersionFormatTest.m [ObjC] Add a test for unknown runtime markers. 2025-03-26 13:10:14 -07:00
GPBMessageTests+Merge.m [ObjC] Use more complete imports 2024-09-05 08:52:31 -07:00
GPBMessageTests+Runtime.m Emit hassers for oneofs in objectivec. 2025-10-08 13:31:34 -07:00
GPBMessageTests+Serialization.m Modify unit tests to use c_function extension syntax via ifdefs 2026-02-26 17:51:54 -08:00
GPBMessageTests.m [ObjC] Add DEBUG-only validations to extension values in GPBMessage, along with tests. 2026-04-20 16:11:48 -07:00
GPBObjectiveCPlusPlusTest.mm [ObjC] Remove the C++ version check in the test. 2025-06-11 10:29:18 -07:00
GPBPerfTests.m Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
GPBSwiftTests.swift [ObjC] Add comment on import for future reference. 2024-07-03 09:50:22 -07:00
GPBTestUtilities.h Fix build in C23 with -Wunused-parameter. 2024-10-07 07:59:45 -07:00
GPBTestUtilities.m Modify unit tests to use c_function extension syntax via ifdefs 2026-02-26 17:51:54 -08:00
GPBUnittestProtos.m Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
GPBUnittestProtos2.m Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
GPBUnknownFieldsTest.m Modify unit tests to use c_function extension syntax via ifdefs 2026-02-26 17:51:54 -08:00
GPBUtilitiesTests.m [ObjC] Fix over-release in GPBTextFormatForMessage 2026-04-06 14:19:57 -07:00
GPBWellKnownTypesTest.m [ObjC] Use more complete imports 2024-09-05 08:52:31 -07:00
GPBWireFormatTests.m [ObjC] Carry recursion depth across MessageSet item parsing (#27571) 2026-08-04 08:41:24 -07:00
map_proto2_unittest.proto Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
map_unittest.proto Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
text_format_extensions_unittest_data.txt Add a unittest for ObjC TextFormat extension support. 2018-11-14 17:06:51 -05:00
text_format_map_unittest_data.txt Alpha 1 drop of Google's Objective C plugin and runtime support for protobufs. 2015-05-06 13:19:14 -04:00
text_format_unittest_data.txt Alpha 1 drop of Google's Objective C plugin and runtime support for protobufs. 2015-05-06 13:19:14 -04:00
unittest.proto This CL starts failing on [unverified_lazy = true] on extensions, which have been 2026-01-15 13:39:23 -08:00
unittest_cycle.proto Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
unittest_deprecated.proto Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
unittest_deprecated_file.proto Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
unittest_extension_chain_a.proto Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
unittest_extension_chain_b.proto Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
unittest_extension_chain_c.proto Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
unittest_extension_chain_d.proto Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
unittest_extension_chain_e.proto Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
unittest_extension_chain_f.proto Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
unittest_extension_chain_g.proto Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
unittest_import.proto Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
unittest_import_public.proto Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
unittest_mset.proto [ObjC] Only promote known extensions in messageset 2025-02-12 08:19:23 -08:00
unittest_objc.proto Fix minor typos (#17682) 2024-09-20 20:50:06 -07:00
unittest_objc_options.proto Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
unittest_objc_startup.proto Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
unittest_preserve_unknown_enum.proto Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
unittest_runtime_proto2.proto Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
unittest_runtime_proto3.proto Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
UnitTests-Bridging-Header.h Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full. 2023-09-08 18:45:55 -07:00
UnitTests-Info.plist Update the min toolchain for iOS/OS X to be Xcode 7 2015-12-10 16:40:10 -05:00