Skip to content

[mono] Prevent theoretical overflow due to excessive aggregation of cmods - #135491

Merged
BrzVlad merged 1 commit into
mainfrom
fix-mono-ovf
Oct 15, 2026
Merged

BrzVlad merged 1 commit into
mainfrom
fix-mono-ovf

Conversation

@BrzVlad

@BrzVlad BrzVlad commented Oct 9, 2026

Copy link
Copy Markdown
Member

A type normally has a small set of custom modifiers, and Mono has a hardcoded limit for them. However, generic inflation can append modifiers without enforcing that limit, while the aggregated count is stored in a uint8_t. Repeated generic instantiations can therefore overflow the count, causing subsequent copies to overflow the allocated buffer. This can be reproduced with a pattern like:

D1<T> : Base<T modopt(A1) ... modopt(A60)>
D2<T> : D1<T modopt(B1) ... modopt(B60)>
D3<T> : D2<T modopt(C1) ... modopt(C60)>
D4<T> : D3<T modopt(D1) ... modopt(D60)>
D5<T> : D4<T modopt(E1) ... modopt(E60)>

Compute the combined count in size_t and assert that it remains below MONO_MAX_EXPECTED_CMODS before narrowing. Types above this limit were not consistently supported; for example, AOT decode_type already asserts the same limit. This doesn't expand support, rather makes the runtime fail in a deterministic way.

…mods

A type normally has a small set of custom modifiers, and Mono has a hardcoded limit for them. However, generic inflation can append modifiers without enforcing that limit, while the aggregated count is stored in a `uint8_t`. Repeated generic instantiations can therefore overflow the count, causing subsequent copies to overflow the allocated buffer. This can be reproduced with a pattern like:

```
D1<T> : Base<T modopt(A1) ... modopt(A60)>
D2<T> : D1<T modopt(B1) ... modopt(B60)>
D3<T> : D2<T modopt(C1) ... modopt(C60)>
D4<T> : D3<T modopt(D1) ... modopt(D60)>
D5<T> : D4<T modopt(E1) ... modopt(E60)>
```

Compute the combined count in `size_t` and assert that it remains below `MONO_MAX_EXPECTED_CMODS` before narrowing. Types above this limit were not consistently supported; for example, AOT `decode_type` already asserts the same limit.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 7fa5e5b9-244d-4bc9-89b0-0f78d69f1a9f
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@BrzVlad
BrzVlad requested a review from lateralusX October 10, 2026 05:35
@BrzVlad
BrzVlad merged commit 5d6d8d8 into main Oct 15, 2026
85 checks passed
@BrzVlad
BrzVlad deleted the fix-mono-ovf branch October 15, 2026 14:10
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 19, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants