Commit graph

1864 commits

Author SHA1 Message Date
Tony Liao
6836552e25 Allow later enum aliases to overwrite in C# custom JSON enum mapping.
When constructing the custom JSON enum name map in C# JsonParser, remove the
ContainsKey check so that subsequent aliased enum values overwrite earlier ones,
aligning with the "last match wins" semantics used across C++, Java, PHP, and Python.

PiperOrigin-RevId: 970656172
2026-08-25 10:50:27 -07:00
Tony Liao
bae5b79a43 Cache custom JSON enum names in JsonParser using Lazy.
Custom JSON enum names are defined in descriptor options and looked up
when parsing JSON strings. Instead of performing a linear scan over
Values on each lookup, this change adds a ConcurrentDictionary with
Lazy<Dictionary> to JsonParser to lazily construct and cache the JSON
name to EnumValueDescriptor lookup table per EnumDescriptor on first
access.

Lazy provides thread-safe, lock-free reads on all subsequent accesses.

PiperOrigin-RevId: 963583475
2026-08-12 12:05:11 -07:00
Protobuf Team Bot
e49cfc58ea Auto-generate files after cl/963493738 2026-08-12 16:46:18 +00:00
Tony Liao
692daead2a csharp: add support for custom json strings for enum values
PiperOrigin-RevId: 963493738
2026-08-12 09:35:57 -07:00
Protobuf Team Bot
51dedb854d Auto-generate files after cl/958447202 2026-08-03 17:36:17 +00:00
Protobuf Team Bot
e5fbe9531a Auto-generate files after cl/957685462 2026-08-01 19:20:06 +00:00
Jason Aragorn Tobias Lunn
713b6a4a24 Add json_options.proto and json_enumvalue_options.proto and/or gencode derived from them to release artifacts
* `protoc`: Included in zips alongside binary
* Java: Generated classes have been added to the Maven `util` artifact
* Ruby: Generated classes have been added to gems
* CMake: `.proto` files are included in installation

PiperOrigin-RevId: 957382561
2026-07-31 16:20:59 -07:00
Protobuf Team Bot
b7491e2dc3 Auto-generate files after cl/953801430 2026-07-25 09:56:59 +00:00
rgoldfinger6
4b269eb436 Updating version.json and repo version numbers to: 37.0-dev (#28425)
NOTE: This should be reviewed and imported via Copybara per the normal PR review process.

Closes #28425

PiperOrigin-RevId: 945675238
2026-07-10 06:22:59 -07:00
Protobuf Team Bot
342944aa64 Auto-generate files after cl/944424868 2026-07-08 11:48:06 +00:00
Jason Aragorn Tobias Lunn
636ae747e6 Update our compiled_edition_default's maximum_edition to 2026
PiperOrigin-RevId: 944116273
2026-07-07 15:13:49 -07:00
Protobuf Team Bot
da161add15 Auto-generate files after cl/938151844 2026-06-25 20:21:21 +00:00
Protobuf Team Bot
3b19a198fa Suppress C# unused import warning spam in deep imports test by using import public.
PiperOrigin-RevId: 934731314
2026-06-18 22:32:51 -07:00
Protobuf Team Bot
594a11afc7 Auto-generate files after cl/933149227 2026-06-16 17:14:31 +00:00
Protobuf Team Bot
d8425ef706 Auto-generate files after cl/928436147 2026-06-08 09:50:13 +00:00
Protobuf Team Bot
a1f718cdd7 Advertise that C# supports Edition 2026, and move C# Nullable Reference Type support into that edition.
PiperOrigin-RevId: 928390507
2026-06-08 00:56:32 -07:00
Protobuf Team Bot
cc2ae8ea97 Auto-generate files after cl/926158387 2026-06-03 18:37:22 +00:00
Protobuf Team Bot
447cba6a09 Auto-generate files after cl/926073660 2026-06-03 16:31:21 +00:00
Protobuf Team Bot
7a732d1fb8 First implementation of C# nullable reference types enablement using the current (unreleased) edition.
PiperOrigin-RevId: 926073660
2026-06-03 09:21:54 -07:00
Fernando Garcia Corona
aeb0dc2f97 Fix for performance penalty in deep dependencies (#20392)
The goal of this PR is to fix #20371 (closed) #24267 and #24330 and improve the performance of csharp runtime when dealing with deep nested dependencies of .proto files.

- The fix consists in caching the recursive calls for the search of extensions.

- Two identical datasets (nested proto files) are created automatically using Bazel: one to test it with caching enabled, and another one to test it with no caching. Note: the same dataset cannot be used because once it is loaded inside the test, it cannot be unloaded.

- The created datasets have a width of 6 and a depth of 6, enough to showcase the dependency impact and to not impact the testing time for unit tests. This could be configured.

- In the dataset there is only one proto file with a message `Example` whose descriptor is loaded, and by doing so all the dependencies (and sub dependencies) that it has.

- A set of benchmark metrics have been created to evaluate the performance impact before and after the fix.

- The assertion inside the unit test makes sure that when using metrics the number of traversed extensions (dependencies of the dependencies) when using caching, is reduced by a factor of 1000x.

- The second assertion also makes sure that the time used to load the descriptor when using cache is less than the one without using cache.

Closes #20392

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/20392 from fgarciacorona:fix_20371_csharp_deep_dependencies b1353f6fd1
PiperOrigin-RevId: 919713760
2026-05-22 09:26:03 -07:00
Sandy Zhang
2c15ca43cf Upgrade C# Protobuf projects to .NET 8.0.
This change updates the target frameworks for various C# projects within Protobuf to .NET 8.0, while also maintaining netstandard2.0 for the core library. Support for older frameworks like net45, net50, and netstandard1.1 has been removed.

This updates our project to match our support policy in https://github.com/google/oss-policies-info/blob/main/foundational-dotnet-support-matrix.md which actually dropped support for net45, net50, etc long ago.

PiperOrigin-RevId: 919111969
2026-05-21 10:07:55 -07:00
Paweł Łukasik
fe9848e7b3 C#: fix IndexOutOfRangeException in ReadRawByte on truncated messages (#26914)
**Summary**
A near-int.MaxValue length varint overflows PushLimit, corrupting bufferSize to a negative value. ReadRawByte's == guard then never triggers RefillBuffer, causing an out-of-bounds read instead of InvalidProtocolBufferException.TruncatedMessage().

**Fix**
change == to >= in ReadRawByte. Regression tests added for all four affected slow-path variants.

**Tests**
Added `TruncatedMessageWithLargeInnerLengthThrowsInvalidProtocolBufferException` with 4 test cases.

Fixes #26856

Closes #26914

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/26914 from pawlos:fix/csharp-readrawbyte-ioob-truncated-message 6bec67cfb2
PiperOrigin-RevId: 914940764
2026-05-13 10:41:16 -07:00
Protobuf Team Bot
21966dce54 Auto-generate files after cl/912565711 2026-05-08 16:52:21 +00:00
Rachel Goldfinger
1da22aa3b9 Update JsonParser settings creation in Conformance tests to use default recursion limit.
PiperOrigin-RevId: 910891579
2026-05-05 13:50:40 -07:00
Protobuf Team Bot
a8896e84d6 Auto-generate files after cl/908404027 2026-04-30 22:31:44 +00:00
Mindflare
cee45bff13 csharp: propagate recursion depth into JsonReplayTokenizer to honor Any nesting limit (#26835)
## Summary

`JsonParser.MergeAny()` records the JSON token stream of an Any body and replays it through a fresh `JsonReplayTokenizer` to parse the inner message. The replay tokenizer's `RecursionDepth` was never initialized from the parent tokenizer, so it defaulted to zero — and the recursion-depth check in `JsonParser.Merge()` reads the **tokenizer's** depth field. As a result, every nested `google.protobuf.Any` started at depth zero and the `Settings.RecursionLimit` check never fired.

A pathological JSON document such as

```json
{"@type":"type.googleapis.com/google.protobuf.Any","value":
 {"@type":"type.googleapis.com/google.protobuf.Any","value":
  {"@type":"type.googleapis.com/google.protobuf.Any","value": ... }}}
```

recurses through `MergeAny -> MergeWellKnownTypeAnyBody -> Merge -> MergeAny -> ...` until the .NET stack is exhausted, raising an uncatchable `StackOverflowException` and terminating the host process.

The pre-existing `// FIXME: Object depth not maintained...` comment in `JsonReplayTokenizer` already acknowledged the gap.

## Prior art

The same bug class has previously been fixed in the sibling language implementations of protobuf:

- **Java** — `mergeAnyMessage` was missing the `currentDepth` increment.
- **Python** — `_ConvertAnyMessage` reached via `methodcaller(...)` bypassed the depth tracking.

The C# `MergeAny` path was overlooked at the time. A C# *array* recursion fix landed previously, but the Any case was not covered.

## Fix

Inherit the parent tokenizer's `RecursionDepth` when constructing a `JsonReplayTokenizer`, so that `JsonParser.Merge()`'s existing limit check applies across the replay boundary.

```csharp
internal JsonReplayTokenizer(IList<JsonToken> tokens, JsonTokenizer nextTokenizer)
{
    this.tokens = tokens;
    this.nextTokenizer = nextTokenizer;
    this.RecursionDepth = nextTokenizer.RecursionDepth;
}
```

## Tests

Added `JsonParserTest.MaliciousRecursionOfAnyInAny`, mirroring the existing `MaliciousRecursionOfObjectsInValue` / `MaliciousRecursionOfArraysInValue` regression tests:

- Builds a 100-deep Any-of-Any document.
- A parser with a generous limit parses it without exception.
- A parser with an insufficient limit throws `InvalidProtocolBufferException` (rather than overflowing the stack).

Without the fix, the second assertion either spins past the configured limit (because each replay tokenizer resets depth to zero) or terminates the test runner with `StackOverflowException`.

Closes #26835

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/26835 from MindflareX:fix/csharp-any-recursion-depth 8d5f5792a0
PiperOrigin-RevId: 904564398
2026-04-23 11:51:16 -07:00
Protobuf Team Bot
2bbe9efe6a Auto-generate files after cl/904524464 2026-04-23 17:51:21 +00:00
Protobuf Team Bot
30b067fd78 Auto-generate files after cl/903894356 2026-04-22 16:51:38 +00:00
Andrey Zhabsky
a29828239f Fix csharp string interpolation in Timestamp.ToDateTime() exception message (#26341)
Change a verbatim string literal `@""` to an interpolated string `$""` in `Timestamp.ToDateTime()` exception message.
Resolves #26006.

Closes #26341

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/26341 from tyulpan:fix-csharp-timestamp-exception-message e102d1276a
PiperOrigin-RevId: 903792535
2026-04-22 05:52:19 -07:00
Samuel Benzaquen
e6ee74af87 Updating version.json and repo version numbers to: 36.0-dev (#26991)
NOTE: This should be reviewed and imported via Copybara per the normal PR review process.

Closes #26991

PiperOrigin-RevId: 902788011
2026-04-20 13:14:04 -07:00
Protobuf Team Bot
106f474ff7 Auto-generate files after cl/897865962 2026-04-10 20:52:49 +00:00
Protobuf Team Bot
1f565a2d02 Auto-generate files after cl/896589647 2026-04-08 18:06:51 +00:00
Protobuf Team Bot
1ffc1a2a22 Auto-generate files after cl/895988455 2026-04-07 18:09:27 +00:00
Protobuf Team Bot
311d19eca5 Auto-generate files after cl/894188732 2026-04-03 19:12:45 +00:00
Protobuf Team Bot
a2d8cab71e Auto-generate files after cl/893619358 2026-04-02 18:56:32 +00:00
Protobuf Team Bot
a19901d3c6 Auto-generate files after cl/890289024 2026-03-27 07:59:14 +00:00
Protobuf Team Bot
2893999a3c feat: add initially-empty C# features proto
PiperOrigin-RevId: 890289024
2026-03-27 00:50:02 -07:00
Protobuf Team Bot
37c86589ca Auto-generate files after cl/889848633 2026-03-26 15:21:43 +00:00
Protobuf Team Bot
25445bc7e1 Auto-generate files after PR #26455 2026-03-19 04:37:34 +00:00
Lethe
cf3a0ea109 C#: Fix redundant has_bits alloc for multi of 32 (#26455)
### Description
This PR fixes the issue where an unused `_hasBits` field is allocated in the generated C# code when the number of presence bits is an exact multiple of 32.

**Changes:**
- Updated the `has_bit_field_count_` calculation in `MessageGenerator` to use the formula: `(presence_bit_count + 31) / 32`.
- This ensures that exactly 1 `int32` is allocated for 32 fields, 2 for 64 fields, etc., instead of over-allocating.

**Testing:**
- Added `TestPresenceBits` to `unittest_issues.proto` which includes exactly 32 optional fields.
- Added a unit test in `Proto3OptionalTest.cs` to assert that exactly one `_hasBits0` field is generated via reflection.

Fixes #26391

Closes #26455

PiperOrigin-RevId: 885948073
2026-03-18 21:27:46 -07:00
Protobuf Team Bot
147d72fdca Auto-generate files after cl/884566997 2026-03-16 19:11:11 +00:00
Protobuf Team Bot
6867822087 Auto-generate files after cl/884474939 2026-03-16 16:26:17 +00:00
Jie Luo
7fd0570f32 Remove "//conformance:all_files" dep from bootstrap_unittest
PiperOrigin-RevId: 882094646
2026-03-11 10:47:57 -07:00
Jie Luo
efd47196d8 Add conformance performance test suite for csharp (#26194)
Closes #26194

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/26194 from protocolbuffers:conformance_performance 2d2ac3685c
PiperOrigin-RevId: 880822155
2026-03-09 06:25:24 -07:00
Protobuf Team Bot
56d27b7900 Auto-generate files after cl/879595940 2026-03-06 14:29:50 +00:00
Protobuf Team Bot
56f4217399 Auto-generate files after cl/872104661 2026-02-19 01:07:24 +00:00
Protobuf Team Bot
9caab4ca54 Auto-generate files after cl/871924862 2026-02-18 18:17:08 +00:00
Protobuf Team Bot
3c7f4a4bd2 Auto-generate files after cl/871710158 2026-02-18 08:38:52 +00:00
Protobuf Team Bot
e25ded8920 Auto-generate files after cl/869236784 2026-02-12 16:57:23 +00:00
Protobuf Team Bot
2aa094e0d3 Auto-generate files after cl/864384082 2026-02-02 17:22:39 +00:00