[PR #2696] [CLOSED] fix(dotnet): name the instruction when a truncated operand leaves the method body #5319

Closed
opened 2026-10-31 01:05:42 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/2696
Author: @aftabkh4n
Created: 10/13/2026
Status: ❌ Closed

Base: main ← Head: fix/dotnet-truncated-operand-diagnostic


📝 Commits (4)

  • 10a3de5 fix(dotnet): name the instruction when a truncated operand leaves the method body
  • f194d9c chore: merge main and resolve PR #2696 conflicts
  • 6462483 chore: merge captured main into PR #2696
  • 153bba4 Merge branch 'main' into fix/dotnet-truncated-operand-diagnostic

📊 Changes

2 files changed (+104 additions, -84 deletions)

View changed files

📝 src/dotnet/ManagedCilDecoding.test.ts (+8 -0)
📝 src/dotnet/ManagedMemberInstructionDecoder.ts (+96 -84)

📄 Description

Summary

Fixes #2677. When a managed method's last instruction has an incomplete operand, body.issue reported a raw Node Buffer error instead of the decoder's existing format diagnostic, losing the opcode and IL offset.

Problem and expected behavior

Smallest trigger: a tiny method body whose one IL byte is ldc.i4 (0x20) with no operand. Before: "issue": "Attempt to access memory outside buffer bounds" (or The value of "offset" is out of range… for 1-byte operands). Expected: "Instruction ldc.i4 at IL offset 0 leaves method body", with status: "malformed", the decoded prefix, and a null normalized hash unchanged.

Change and scope

The producing boundary is readOperand in ManagedMemberInstructionDecoder.ts. Each fixed-width operand reader now declares its width, and switch counts and metadata tokens check their 4 bytes, so a short operand is detected before any read and routed to the existing "leaves method body" diagnostic. A two-byte opcode truncated after its 0xfe prefix gets the same treatment. The generic catch remains for unrelated failures. Out of scope: other wording in body.issue.

Contribution scope: ordinary fix within existing boundaries; maintainer scope decision not applicable.

Contract and boundary impact

  • Semantic owner and earliest changed stage: src/dotnet/ManagedMemberInstructionDecoder.ts, operand decoding.

  • Contribution scope fit and linked maintainer decision: in scope (static format inspection); not applicable.

  • CLI and MCP/tool-catalog contract: no schema change; only the body.issue text for truncated operands changes.

  • Provider, bridge, target-format, or platform compatibility: none.

  • Evidence, artifact, provenance, or reconstruction contract: malformed status, decoded prefix, and null normalized IL hash preserved.

  • Target selection, authority, upstream behavior, and cleanup details: not applicable.

  • Generated metadata, package, or installation impact: none.

  • Read existing files or captured data.

Evidence and regression coverage

  • Tests added or updated: src/dotnet/ManagedCilDecoding.test.ts, "managed CIL operand truncation": truncated ldc.i4 (alone and after nop, which is kept), br.s, ldloc, a switch count, and a two-byte opcode prefix.

  • Base reproduction: on the base revision all 6 cases fail with the raw Buffer/RangeError messages reported in the issue; with the fix they pass.

  • User-visible CLI/MCP output: body.issue now reads e.g. Instruction ldc.i4 at IL offset 0 leaves method body.

  • Remaining proof gaps: CLI/MCP transport not executed end to end; covered through inspectManagedMembersBytes, the production entry the provider uses.

  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run test:local -- src/dotnet/ManagedCilDecoding.test.ts: 33 passed (6 failed before the fix)
  • npm run test:local -- src/dotnet/*.test.ts: 11 files, 189 tests passed
  • npm run check:fast: typecheck and lint pass
  • npm run verify:test-discovery: all 1037 test files discovered once

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable (pure static decoder).
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no new target interaction; bounds are checked before reads.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/2696 **Author:** [@aftabkh4n](https://github.com/aftabkh4n) **Created:** 10/13/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/dotnet-truncated-operand-diagnostic` --- ### 📝 Commits (4) - [`10a3de5`](https://github.com/morluto/rea/commit/10a3de5a855a4be63da522bbb4de26bbc7eface4) fix(dotnet): name the instruction when a truncated operand leaves the method body - [`f194d9c`](https://github.com/morluto/rea/commit/f194d9c02f41d7cba04c22f4c571a571ec18513f) chore: merge main and resolve PR #2696 conflicts - [`6462483`](https://github.com/morluto/rea/commit/646248334a6c9c60ca9546aedcbcdddc1609d0de) chore: merge captured main into PR #2696 - [`153bba4`](https://github.com/morluto/rea/commit/153bba4e980597b2e0778e07258b2d15b5606d53) Merge branch 'main' into fix/dotnet-truncated-operand-diagnostic ### 📊 Changes **2 files changed** (+104 additions, -84 deletions) <details> <summary>View changed files</summary> 📝 `src/dotnet/ManagedCilDecoding.test.ts` (+8 -0) 📝 `src/dotnet/ManagedMemberInstructionDecoder.ts` (+96 -84) </details> ### 📄 Description ## Summary Fixes #2677. When a managed method's last instruction has an incomplete operand, `body.issue` reported a raw Node Buffer error instead of the decoder's existing format diagnostic, losing the opcode and IL offset. ## Problem and expected behavior Smallest trigger: a tiny method body whose one IL byte is `ldc.i4` (`0x20`) with no operand. Before: `"issue": "Attempt to access memory outside buffer bounds"` (or `The value of "offset" is out of range…` for 1-byte operands). Expected: `"Instruction ldc.i4 at IL offset 0 leaves method body"`, with `status: "malformed"`, the decoded prefix, and a null normalized hash unchanged. ## Change and scope The producing boundary is `readOperand` in `ManagedMemberInstructionDecoder.ts`. Each fixed-width operand reader now declares its width, and switch counts and metadata tokens check their 4 bytes, so a short operand is detected before any read and routed to the existing "leaves method body" diagnostic. A two-byte opcode truncated after its `0xfe` prefix gets the same treatment. The generic catch remains for unrelated failures. Out of scope: other wording in `body.issue`. Contribution scope: ordinary fix within existing boundaries; maintainer scope decision not applicable. ## Contract and boundary impact - Semantic owner and earliest changed stage: `src/dotnet/ManagedMemberInstructionDecoder.ts`, operand decoding. - Contribution scope fit and linked maintainer decision: in scope (static format inspection); not applicable. - CLI and MCP/tool-catalog contract: no schema change; only the `body.issue` text for truncated operands changes. - Provider, bridge, target-format, or platform compatibility: none. - Evidence, artifact, provenance, or reconstruction contract: malformed status, decoded prefix, and null normalized IL hash preserved. - Target selection, authority, upstream behavior, and cleanup details: not applicable. - Generated metadata, package, or installation impact: none. - [x] Read existing files or captured data. ## Evidence and regression coverage - Tests added or updated: `src/dotnet/ManagedCilDecoding.test.ts`, "managed CIL operand truncation": truncated `ldc.i4` (alone and after `nop`, which is kept), `br.s`, `ldloc`, a `switch` count, and a two-byte opcode prefix. - Base reproduction: on the base revision all 6 cases fail with the raw Buffer/RangeError messages reported in the issue; with the fix they pass. - User-visible CLI/MCP output: `body.issue` now reads e.g. `Instruction ldc.i4 at IL offset 0 leaves method body`. - Remaining proof gaps: CLI/MCP transport not executed end to end; covered through `inspectManagedMembersBytes`, the production entry the provider uses. - [x] Unsupported, incomplete, unavailable, or uncertain outcomes remain visible. ## Validation performed - `npm run test:local -- src/dotnet/ManagedCilDecoding.test.ts`: 33 passed (6 failed before the fix) - `npm run test:local -- src/dotnet/*.test.ts`: 11 files, 189 tests passed - `npm run check:fast`: typecheck and lint pass - `npm run verify:test-discovery`: all 1037 test files discovered once ## Compatibility, safety, and release - Breaking changes or migration steps: none. - Real Hopper/Ghidra, browser, or OS coverage: not applicable (pure static decoder). - Package or release metadata impact: none. - Security, privacy, process, or containment review: no new target interaction; bounds are checked before reads. ## Before merge - [x] This PR addresses a concrete problem or an agreed enhancement. - [x] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [x] The PR has one focused outcome and the title follows `type(scope): outcome`. - [x] Related issue is linked, or the reason for not linking one is stated above. - [x] Tests cover changed observable behavior and meaningful failure paths. - [x] Owning docs, contracts, and generated metadata are updated where needed. - [x] User-visible CLI/MCP changes include representative output. - [x] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 01:05:42 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#5319
No description provided.