Repository navigation
fix(dotnet): name the truncated instruction when an operand leaves the method body - #2704
Conversation
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. |
|
…e method body The extent guard ran after the operand read, so a truncated operand threw a raw Buffer RangeError that replaced the intended diagnostic with the runtime message and lost the instruction identity. Bound the operand extent before reading its value and carry the width beside each fixed reader so the two facts cannot drift. Fixes morluto#2677
f0a84dd to
1e9af71
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a4e87eea00
ℹ️ 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".
|
Source fixes and publication evidence for the review findings below. Tests and executable checks were skipped at the maintainer's request. Findings that still require a decision or execution evidence remain open. Two tiny-operand truncation tests duplicated the helper and suite. The tests now use one tiny-body builder and one operand-extent suite, retaining distinct |
The describe block merged from main (morluto#2704) runs 162 lines, over the 150-line lint bound, so the operand-width matrix moves into its own describe. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Summary
decodeInstructionschecked the operand extent only after reading the operand value. Every fixed reader and the token path call NodeBufferreaders that throw aRangeErroronce the operand runs past the end of the IL body. ThatRangeErrorwas caught and its raw runtime message becamebody.issue, so a truncated method body reported"Attempt to access memory outside buffer bounds"instead of naming the instruction.This bounds the operand extent before reading, so the existing
Instruction <name> at IL offset <n> leaves method bodydiagnostic wins.Problem and expected behavior
Reporter's case —
buildManagedPeFixture({ ilBody: Buffer.from([0x06, 0x20]) })(ldloc.0; ldc.i4with no operand) throughinspectManagedMembersBytes/managedPeFixtureTarget:"issue": "Attempt to access memory outside buffer bounds""issue": "Instruction ldc.i4 at IL offset 0 leaves method body"Verified on the merge base:
status: "malformed",coverage: "partial"andnormalized_il_sha256: nullare unchanged — only the diagnostic text improves.Change and scope
src/dotnet/ManagedMemberInstructionDecoder.tsoperandExtent(il, offset, kind)computes the operand width without reading it: fixed widths from the table,4 + count * 4forswitch(returningnullwhen the count field itself is unreadable), and4for token kinds.FIXED_OPERAND_READERSbecomesMap<string, FixedOperand>={ width, read }, so each reader's byte width sits beside the read that uses it. The width and the reader can no longer drift apart.decodeInstructionsnow checks the extent before callingreadOperand, and the old post-readoperand.next < offset || operand.next > il.lengthguard is deleted.next < offsetwas dead — every reader returnsoffset + non-negative.readOperand's unknown-kind branch returns without reading (it previously read 4 bytes yet reported extent 0). The branch is unreachable from the closedOPCODEStable, so behaviour is unchanged; the inconsistency is removed rather than left as a trap.TOKEN_OPERAND_KINDSmoved above its consumers to avoid use-before-declaration.src/dotnet/ManagedCilDecoding.test.ts— newdescribe("managed operand extent diagnostics"), 39 tests.No change to
ManagedMethodBodyReader.ts, the public CLI/MCP contracts, or any output shape.Contract and boundary impact
The fix is at the producing boundary — the place that decides an operand is out of range — rather than a downstream repair of the message.
body.issueremainsdecoded.issue ?? malformed-regions ?? truncated-fallbackatsrc/dotnet/ManagedMethodBodyReader.ts:175, sostatus: "malformed",coverage: "partial",decoded_instruction_countand the nullnormalized_il_sha256are all preserved exactly as before.Evidence and regression coverage
Coverage is in both directions, because a width that is wrong in either direction reintroduces the raw buffer error or wrongly rejects a valid operand:
0Mutation-checked rather than assumed:
ldc.i4width 4 → 3ldc.i4width 4 → 5ldc.r4width 4 → 8TOKEN_OPERAND_WIDTH4 → 2With the decoder reverted, 16 of the 19 original zero-byte tests fail and all 27 pre-existing tests pass either way. The 3 that pass both ways are the two controls plus the readable-count
switchcase, which the oldoperand.nextguard already handled.The new tests assert the instruction name, offset and decoded value, not just that the message changed, so no generic message would satisfy them.
Validation performed
npm run test:local -- src/dotnet/ManagedCilDecoding.test.tsnpm run test:local --(all 11src/dotnet/*.test.ts)npm run check:fastnpm run verify:test-discoverynpx oxfmt --checkon both changed filesNode 24.15.0 / npm 11.12.1, Windows x64.
npm run docs:checkpasses 4/5 tasks here;artifacts:managed-evidencefails withEPERM ... mkdtempon this host — I confirmed it fails identically on a clean checkout, so it is environmental, not caused by this change.Not verified: no real managed
.exe/.dllfixture and no real-provider run — this is a diagnostic-wording fix validated entirely on the syntheticManagedPe.fixture.tsfixtures.Compatibility, safety, and release
"Attempt to access memory outside buffer bounds"string would need to relax that match — unlikely, and the new text is the more useful contract.fix.Before merge
decodeInstructions' operand paths, but I have not auditedManagedMemberInstructionDecoder.ts's callers beyondManagedMethodBodyReader.ts.