[http-client-csharp] Bounds check dynamic model collection paths - #11632
Open
JoshLove-msft wants to merge 2 commits into
Open
[http-client-csharp] Bounds check dynamic model collection paths#11632JoshLove-msft wants to merge 2 commits into
JoshLove-msft wants to merge 2 commits into
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 75b76ced-95ca-4f9d-a46a-2a49e764d549
JoshLove-msft
requested review from
Jorge Rangel (jorgerangel-msft),
Jose Arriaga Maldonado (joseharriaga),
Jesse Squire (jsquire) and
m-nash
as code owners
August 12, 2026 05:31
commit: |
Contributor
|
No changes needing a change description found. |
JoshLove-msft
enabled auto-merge
August 12, 2026 05:42
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 75b76ced-95ca-4f9d-a46a-2a49e764d549
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the http-client-csharp generator to prevent out-of-range indexing when traversing dynamic-model collection properties via JsonPatch propagation, ensuring TryGetValue/Set follow their non-throwing contract for invalid paths.
Changes:
- Emit bounds checks for collection index segments in generated
PropagateGetandPropagateSet, including nested collection paths. - Update generator golden-output test data to reflect the new guards.
- Add end-to-end regression tests validating out-of-range indexed paths return
false(forTryGetValue) and do not throw (forSet) in the Sample_TypeSpec test project.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/MrwSerializationTypeDefinition.Dynamic.cs | Adds generator logic to emit index >= (Count/Length) guards before indexing into lists/arrays during propagation. |
| packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/src/Generated/Models/DynamicModel.Serialization.cs | Updates sample generated output to include the new bounds checks in PropagateGet/PropagateSet across multiple collection shapes. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/DynamicModelSerializationTests/PropagateModelListProperty.cs | Updates expected generated output to include bounds checking for list index access. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/DynamicModelSerializationTests/PropagateMultipleDynamicProperties.cs | Updates expected generated output to include bounds checks for multiple and nested collection propagations. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/DynamicModelSerializationTests/PropagateCustomizedDynamicListProperty.cs | Updates expected output to include bounds checks for customized dynamic list propagation. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/DynamicModelSerializationTests/PropagateCustomizedDynamicListPropertyMixed.cs | Updates expected output to include bounds checks for mixed customized dynamic list propagation. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Sample_TypeSpec/DynamicModelTests.cs | Adds E2E regression tests covering out-of-range collection paths for JsonPatch.TryGetValue and JsonPatch.Set. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PropagateGetandPropagateSet, including nested collectionsJsonPatch.TryGetValueandJsonPatch.SetFixes #11616
Validation
npm run buildnpm testnpm run copdotnet test Microsoft.TypeSpec.Generator.ClientModel.Tests.csproj(1,560 passed)