Skip to content

fix(managed): decode generic, array, fnptr, and modifier signatures - #1835

Merged
kaoru0822-kitauji merged 6 commits into
mainfrom
fix/managed-signature-element-types
Oct 11, 2026
Merged

kaoru0822-kitauji merged 6 commits into
mainfrom
fix/managed-signature-element-types

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Summary

Fixes #1832.

inspect_managed_members reported ordinary ECMA-335 member signatures as parse_status: "unsupported" when they used:

  • GENERICINST (0x15)
  • ARRAY (0x14)
  • FNPTR (0x1b)
  • CMOD_REQD and CMOD_OPT (0x1f/0x20)
  • TYPEDBYREF (0x16)

Those members got no return_type, parameter_types, or field_type, and the whole inspection dropped to coverage.state: "partial". That happens for any assembly with generic members, such as Dictionary<string, object>.

Change

readTypeSignature now 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.

Element type Rendering
GENERICINST class:113<string>, valuetype:10<var:0,mvar:1>
ARRAY ILAsm bounds: i4[1...4,-1...1], string[5,,], and i4[...] for an unbounded rank-1 array (bare [] stays reserved for SZARRAY)
FNPTR fnptr[<calling convention>](params)->return
CMOD_REQD / CMOD_OPT i4 modreq:9, i4 modopt:13*
TYPEDBYREF typedbyref
  • Class and valuetype operands keep their encoded TypeDefOrRefOrSpec values, as before.
  • raw_length and raw_sha256 are unchanged.

What still does not decode:

  • Malformed shapes report 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.
  • Element types that member signatures don't assign still report unsupported. Vararg sentinels (0x41) are among these; I left them out so parameter_types stays consistent with parameter_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.ts gains:
  • npm run test:focused passes on the managed source, boundary, and MCP suites (20 files, 173 tests).
  • npm run check:fast and npm run docs:check pass.
  • Not run against System.Runtime.Caching.dll or other real framework assemblies; this macOS host has no .NET install.

🤖 Generated with Claude Code

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]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-11T14:40:50.846516Z f013f9f New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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}` });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

Comment on lines +521 to +522
const header = readMethodSignatureHeader(blob, cursor + 1);
const convention = callingConvention(header.first);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

kaoru0822-kitauji and others added 2 commits October 11, 2026 13:49

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +536 to +539
if (
!FUNCTION_POINTER_CONVENTIONS.has(header.first & 0x0f) ||
(header.first & 0x80) !== 0
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

Comment on lines +506 to +508
} else if (kind === 0x16) {
value = "typedbyref";
cursor += 1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +549 to +553
kind: "list",
remaining: argumentCount.value,
items: [],
signatureItems: false,
render: (items) => `${head}<${items.join(",")}>`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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]) and fnptr[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.

Comment on lines +573 to +577
kind: "list",
remaining: header.parameterCount + 1,
items: [],
signatureItems: true,
render: ([returnType, ...parameters]) =>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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]) and fnptr[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]>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

@kaoru0822-kitauji
kaoru0822-kitauji merged commit 1f531fc into main Oct 11, 2026
30 checks passed
@kaoru0822-kitauji
kaoru0822-kitauji deleted the fix/managed-signature-element-types branch October 11, 2026 14:43
@github-actions github-actions Bot mentioned this pull request Oct 11, 2026
3 tasks done
JasonBuildAI added a commit to JasonBuildAI/rea that referenced this pull request Oct 11, 2026
@morluto morluto added bug Something isn't working area: domain Domain logic, errors, and pure functions labels Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: domain Domain logic, errors, and pure functions bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] inspect-managed-members marks generic, array, fnptr, and custom-modifier member signatures unsupported

2 participants