Repository navigation
fix(managed): decode generic, array, fnptr, and modifier signatures - #1835
Conversation
Member signatures using GENERICINST, ARRAY, FNPTR, CMOD_REQD/CMOD_OPT, or TYPEDBYREF were reported as unsupported, leaving their types unknown and turning otherwise complete inspections partial. Decode them with an explicit stack so nested signatures stay recursion-free, keep encoded TypeDefOrRefOrSpec values, and report malformed shapes as malformed. Fixes #1832 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ab83f7a595
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| lowerBounds.push(bound.value); | ||
| next = bound.next; | ||
| } | ||
| const dimensions = Array.from({ length: rank.value }, (_, index) => { |
There was a problem hiding this comment.
Bound array rank before allocating dimensions
A corrupt field signature such as 06 14 08 DF FF FF FF 00 00 encodes an array rank of 0x1fffffff with no sizes or lower bounds. It passes the current checks and then this Array.from attempts to materialize roughly 536 million dimensions before the projection budget can reject the resulting representation, so inspecting a tiny untrusted PE can hang or exhaust the process instead of returning a tagged malformed/resource-limit result. Reject or budget the rank before allocating the dimension array.
AGENTS.md reference: AGENTS.md:L42-L42
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 754aec8. A rank above 32 is now rejected before any dimension is rendered. ECMA-335 sets no rank limit, but the CLR loads at most 32 dimensions, so such a signature is reported as unsupported with its raw hash kept, not as malformed. Your 06 14 08 DF FF FF FF 00 00 example is a test case, alongside a rank-32 array that still decodes. The other counts are already bounded: size and lower-bound counts can't exceed the rank, and each generic argument or function-pointer parameter consumes at least one blob byte.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 754aec8c74
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } else if (kind === 0x1f || kind === 0x20) { | ||
| const token = readCompressed(blob, cursor + 1); | ||
| const modifier = `${kind === 0x1f ? "modreq" : "modopt"}:${String(token.value)}`; | ||
| stack.push({ kind: "wrap", apply: (inner) => `${inner} ${modifier}` }); |
There was a problem hiding this comment.
Preserve source order for adjacent custom modifiers
With two adjacent modifiers, such as field blob [0x06, 0x1f, 0x05, 0x20, 0x09, 0x08], the LIFO continuations render i4 modopt:9 modreq:5 even though the encoded signature declares modreq:5 before modopt:9. Required modifiers can carry semantics, so this reverses observable signature evidence; collect or render adjacent modifiers in their source order.
AGENTS.md reference: AGENTS.md:L21-L21
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 1ecffcb. Adjacent modifiers now stay in one group in source order, so [0x06, 0x1f, 0x05, 0x20, 0x09, 0x08] renders i4 modreq:5 modopt:9. I kept them as a suffix group rather than switching to prefixes: PTR CMOD i4 and CMOD PTR i4 would both render as modopt:N i4*, and comparisons use these strings as matching keys. Both cases are tested.
| const header = readMethodSignatureHeader(blob, cursor + 1); | ||
| const convention = callingConvention(header.first); |
There was a problem hiding this comment.
Reject invalid function-pointer calling conventions
A field containing FNPTR FIELD 0 void ([0x06, 0x1b, 0x06, 0x00, 0x01]) is reported as decoded as fnptr[field]()->void, because the embedded header is accepted without validating its convention. ECMA-335's Type grammar permits FNPTR only with MethodDefSig or MethodRefSig headers, so FIELD, unmanaged bases, and reserved bits are malformed here; reject them through the existing tagged malformed path rather than allowing complete coverage.
AGENTS.md reference: AGENTS.md:L21-L21
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 1ecffcb. The FNPTR header must now carry a method-signature convention, and reserved bit 0x80 is rejected. FIELD and [0x06, 0x1b, 0x06, 0x00, 0x01] are now malformed. LOCAL_SIG, PROPERTY, GENERICINST, and other unassigned bases are rejected the same way. I kept the unmanaged bases (C, STDCALL, THISCALL, FASTCALL, and the .NET 5+ UNMANAGED base 9) because compilers emit them for C# delegate* unmanaged[...] function pointers; rejecting them would mark real assemblies malformed. They now render with names, e.g. fnptr[c](native-int)->void, instead of unknown:N.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-element-types # Conflicts: # src/dotnet/ManagedMemberInspector.ts
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 144fa3be67
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if ( | ||
| !FUNCTION_POINTER_CONVENTIONS.has(header.first & 0x0f) || | ||
| (header.first & 0x80) !== 0 | ||
| ) |
There was a problem hiding this comment.
Reject invalid function-pointer flag combinations
A function pointer header with EXPLICITTHIS but no HASTHIS, such as field blob [0x06, 0x1b, 0x40, 0x00, 0x01], passes this check and is reported as decoded (fnptr[default explicit-this]()->void). ECMA-335 requires HASTHIS whenever EXPLICITTHIS is set, so this corrupt signature should take the existing malformed path rather than contribute complete signature coverage and structural matching data.
AGENTS.md reference: AGENTS.md:L21-L21
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 2e0f0e2. A FNPTR header with EXPLICITTHIS (0x40) but no HASTHIS (0x20) is now malformed; [0x06, 0x1b, 0x40, 0x00, 0x01] is a test case.
| } else if (kind === 0x16) { | ||
| value = "typedbyref"; | ||
| cursor += 1; |
There was a problem hiding this comment.
Reject typed references in field signatures
ELEMENT_TYPE_TYPEDBYREF is legal as a Param or RetType alternative, not as the Type required by a FieldSig. Consequently the new direct field blob [0x06, 0x16] is invalid metadata but this branch reports it as decoded with field_type: "typedbyref", allowing a malformed field to make the member inventory appear complete; parse the type in its field/parameter/return context and reject this field form.
AGENTS.md reference: AGENTS.md:L21-L21
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 2e0f0e2. TYPEDBYREF now decodes only in a RetType or Param position, optionally after custom modifiers. That covers a method's return and parameters, and the return and parameters of a FNPTR. A field type, a generic argument, an array element, and a modified field type are now malformed; [0x06, 0x16] is among the tests. Tests also cover the accepted forms: typedbyref as return, typedbyref modopt:9 as a parameter, and a FNPTR parameter.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2e0f0e2f62
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| kind: "list", | ||
| remaining: argumentCount.value, | ||
| items: [], | ||
| signatureItems: false, | ||
| render: (items) => `${head}<${items.join(",")}>`, |
There was a problem hiding this comment.
Restrict generic arguments to the Type grammar
A generic argument is a Type, but this list parser still accepts parameter-only forms. For example, [0x06,0x15,0x12,0x05,0x01,0x10,0x08] is decoded as class:5<i4&> even though BYREF is a Param/RetType prefix, not a Type production. This newly supported form therefore marks corrupt field metadata as decoded and lets it participate in structural matching; parse generic-list items in a Type-only context (also excluding other context-only forms).
AGENTS.md reference: AGENTS.md:L21-L21
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in f013f9f, together with the related placement rules. The decoder now tracks each element's position in the ECMA-335 II.23.2 grammar: field type, return type, parameter, nested Type, or pointee. Custom modifiers don't change the position they precede.
- VOID: valid only as a return type or pointee (
void*). - TYPEDBYREF: valid only as a return type or parameter.
- BYREF: valid only at the top of a return type, parameter, or field type. Fields are allowed because ref fields (C# 11) encode as BYREF in FieldSig.
- Function pointer items are parsed as a return type followed by parameters, and generic arguments as Types.
class:5<i4&>([0x06,0x15,0x12,0x05,0x01,0x10,0x08]) andfnptr[default](void)->void([0x06,0x1b,0x00,0x01,0x01,0x01]) are now malformed, along with void fields, void array elements, by-reference pointees, and nested BYREF. Tests cover each rejected form and the valid placements.
| kind: "list", | ||
| remaining: header.parameterCount + 1, | ||
| items: [], | ||
| signatureItems: true, | ||
| render: ([returnType, ...parameters]) => |
There was a problem hiding this comment.
Track function-pointer return and parameter contexts
When a function pointer has a void return and a void parameter ([0x06,0x1b,0x00,0x01,0x01,0x01]), all parameterCount + 1 items are parsed in the same context, so the result is decoded as fnptr[default](void)->void. ECMA-335 permits VOID in a RetType, not in a Param, so this corrupt signature is counted as complete and can feed field structural matching; parse the first item as a return type and later items as parameters.
AGENTS.md reference: AGENTS.md:L21-L21
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in f013f9f, together with the related placement rules. The decoder now tracks each element's position in the ECMA-335 II.23.2 grammar: field type, return type, parameter, nested Type, or pointee. Custom modifiers don't change the position they precede.
- VOID: valid only as a return type or pointee (
void*). - TYPEDBYREF: valid only as a return type or parameter.
- BYREF: valid only at the top of a return type, parameter, or field type. Fields are allowed because ref fields (C# 11) encode as BYREF in FieldSig.
- Function pointer items are parsed as a return type followed by parameters, and generic arguments as Types.
class:5<i4&>([0x06,0x15,0x12,0x05,0x01,0x10,0x08]) andfnptr[default](void)->void([0x06,0x1b,0x00,0x01,0x01,0x01]) are now malformed, along with void fields, void array elements, by-reference pointees, and nested BYREF. Tests cover each rejected form and the valid placements.
Track whether each element is a field type, return type, parameter, nested Type, or pointee. VOID is valid only as a return type or pointee, TYPEDBYREF only as a return type or parameter, and BYREF only at the top of a return type, parameter, or ref field; other placements are malformed. Function pointer items are parsed as a return type then parameters, and generic arguments as Types. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f013f9f28c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const suffix = kind === 0x0f ? "*" : kind === 0x10 ? "&" : "[]"; | ||
| stack.push({ kind: "suffix", suffix }); | ||
| cursor += 1; | ||
| } else if (kind === 0x1f || kind === 0x20) { |
There was a problem hiding this comment.
Reject custom modifiers in invalid grammar positions
A generic argument is a Type, not CustomMod* Type, so the field blob 06 15 12 05 01 20 09 08 is malformed. This unconditional branch instead accepts the CMOD_OPT while a generic-argument list is pending and reports class:5<i4 modopt:9> as decoded, allowing corrupt metadata to contribute complete coverage and structural matching data. Track modifier-eligible positions (field/return/parameter prefixes and PTR/SZARRAY element positions) and reject modifiers elsewhere.
AGENTS.md reference: AGENTS.md:L21-L21
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
I'm keeping this one as is. You're right that the strict II.23.2.12 Type production has no CustomMod* prefix for generic arguments or ARRAY elements. In practice, though, modifiers show up there: C++/CLI emits modified type arguments such as List<int modopt(IsLong)>. The runtime's own System.Reflection.Metadata SignatureDecoder decodes CMOD_REQD/CMOD_OPT as a modified type wherever a type is decoded, and Roslyn's metadata reader keeps custom modifiers on type arguments. Rejecting them would mark real C++/CLI assemblies malformed.
Modifiers don't change what the decoder reports about the type they precede: they render in source order next to it (class:5<i4 modopt:9>), and position rules still apply to the modified element (class:5<modopt:9 void> is still malformed). Since nothing is invented or dropped, accepting them doesn't overstate coverage. The raw_sha256 digest still distinguishes the bytes for exact matching.
Summary
Fixes #1832.
inspect_managed_membersreported ordinary ECMA-335 member signatures asparse_status: "unsupported"when they used:Those members got no
return_type,parameter_types, orfield_type, and the whole inspection dropped tocoverage.state: "partial". That happens for any assembly with generic members, such asDictionary<string, object>.Change
readTypeSignaturenow decodes with an explicit continuation stack. These signatures nest (generic arguments, function-pointer parameters), so this keeps the existing guarantee that decoding never recurses; a new test decodes 4,000 nested generic levels.class:113<string>,valuetype:10<var:0,mvar:1>i4[1...4,-1...1],string[5,,], andi4[...]for an unbounded rank-1 array (bare[]stays reserved for SZARRAY)fnptr[<calling convention>](params)->returni4 modreq:9,i4 modopt:13*typedbyrefraw_lengthandraw_sha256are unchanged.What still does not decode:
malformed: a generic instantiation with no arguments or a non-class/valuetype head, a zero-rank array, more sizes or lower bounds than dimensions, and truncation.unsupported. Vararg sentinels (0x41) are among these; I left them out soparameter_typesstays consistent withparameter_count.The limitation text now lists the decoded forms. One comparison boundary test had used
[0x06, 0x15]as its example of an undecodable field. That blob is now a truncated GENERICINST (malformed), so the test uses the unassigned element type 0x7f to keep its intent.Validation
src/dotnet/ManagedMemberInspector.test.tsgains:20 01 01 15 12 71 01 0eshape) and a generic field signature, which reachescoverage: completenpm run test:focusedpasses on the managed source, boundary, and MCP suites (20 files, 173 tests).npm run check:fastandnpm run docs:checkpass.System.Runtime.Caching.dllor other real framework assemblies; this macOS host has no .NET install.🤖 Generated with Claude Code