Repository navigation
[mono] Prevent theoretical overflow due to excessive aggregation of cmods - #135491
Merged
Merged
Conversation
…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
BrzVlad
requested review from
steveisok,
thaystg and
vitek-karas
as code owners
October 9, 2026 12:26
|
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. |
lateralusX
approved these changes
Oct 15, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
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:Compute the combined count in
size_tand assert that it remains belowMONO_MAX_EXPECTED_CMODSbefore narrowing. Types above this limit were not consistently supported; for example, AOTdecode_typealready asserts the same limit. This doesn't expand support, rather makes the runtime fail in a deterministic way.