Skip to content

Guard generic parameter stack back() access - #1639

Merged
Ryan Shepherd (DefaultRyan) merged 1 commit into
masterfrom
user/defaultryan/guard-generic-param-stack-back
Oct 22, 2026
Merged

Ryan Shepherd (DefaultRyan) merged 1 commit into
masterfrom
user/defaultryan/guard-generic-param-stack-back

Conversation

@DefaultRyan

@DefaultRyan Ryan Shepherd (DefaultRyan) commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Summary

  • add explicit guards before accessing generic_param_stack.back()[var.index] in cppwinrt/type_writers.h
  • throw precise invalid_argument diagnostics when generic parameter context is missing or the index is out of range

Behavior change

For malformed metadata that previously reached an unguarded .back() path, cppwinrt now fails deterministically with actionable error text.

Files updated

  • cppwinrt/type_writers.h

Validation

  • built cppwinrt target from cppwinrt.sln (Debug|x64, v143)
  • verified malformed metadata with an invalid generic type parameter reference now fails with the new guarded exception path

- add explicit checks before using generic_param_stack.back() when rendering GenericTypeIndex
- throw detailed invalid_argument messages for missing generic context and out-of-range generic parameter indexes

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 61a69fb9-fb73-4bf5-b557-d60d7f503390
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

Both invalid-access cases are guarded without changing valid-path behavior, and no unresolved issues were identified.

No open issues 🎉

What changed in this PR

This PR hardens generic type parameter handling in the cppwinrt generator so malformed metadata produces explicit errors instead of invalid container access.

Changes:

  • Checks for an empty generic parameter stack before calling .back().
  • Validates the parameter index before indexing, with diagnostics for both failure cases.
  • Preserves behavior for valid generic parameter references.
File Description
cppwinrt/​type_writers.h Guards generic parameter lookup and reports missing context or out-of-range indices.

Review effort: Balanced

@DefaultRyan
Ryan Shepherd (DefaultRyan) merged commit 9194ca1 into master Oct 22, 2026
90 checks passed
@DefaultRyan
Ryan Shepherd (DefaultRyan) deleted the user/defaultryan/guard-generic-param-stack-back branch October 22, 2026 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants