Skip to content

fix(native): name the exhausted native export allowance by its units - #7754

Closed
ayobamiseun wants to merge 2 commits into
morluto:mainfrom
ayobamiseun:fix/7628-native-export-byte-allowance
Closed

ayobamiseun wants to merge 2 commits into
morluto:mainfrom
ayobamiseun:fix/7628-native-export-byte-allowance

Conversation

@ayobamiseun

@ayobamiseun ayobamiseun commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #7628.

inspect-native-exports refused a PE whose export names exhaust the 16777216-byte retained-text allowance with the correct resource_constraint code, retryable: false, and reported_limits: {boundary: "structure", maximum: 16777216}, but remediation.action said the allowance "is a fixed count". The exhausted limit is a byte budget; the independent 262144-entry ceiling was not reached. Recovery now names the retained-text byte allowance for the byte refusal and keeps count wording for the entry-count refusal.

Problem and expected behavior

Trigger: a PE export directory with 4100 name-table entries aliasing one 4096-byte string (16,793,600 retained bytes, 4100 entries). Violated invariant (docs/design/limits-and-recovery.md, PR #5633): recovery for a fixed allowance names the exhausted limit with its units; byte budgets use fixed-byte wording and count limits use fixed-count wording.

Expected: same refusal, same message and reported maximum, with recovery that identifies the retained-name byte allowance.

Change and scope

  • src/native/exports/NativeExportParser.ts (producing boundary): the two parser allowances now throw NativeExportLimitFailure, a BinaryResourceFailure carrying limit: "rows" | "retained_text", mirroring PeImportLimitFailure. Messages, boundary, and maximum_bytes are unchanged.
  • src/native/exports/NativeExportsProvider.ts (consumer): replaces the single fixedAllowanceOptions(..., "count") branch with limitRecovery(limit, maximum): rows → The 262144-entry native export inventory allowance (count), retained_text → The 16777216-byte native export retained-text allowance (bytes), and an untagged BinaryResourceFailure from the shared BinaryReader structural decoding budget → The native export structural decoding allowance (parser, as PeImportsProvider and PeLoadConfigProvider already describe that reader budget). The provider does not re-interpret message text.
  • Not included: no change to the allowances, the refusal code, retryability, or the error message. The ELF version traversal work failure is already converted to an issue inside the parser and does not reach the provider.

Maintainer scope decision: not applicable (ordinary fix within an existing boundary).

Contract and boundary impact

  • Semantic owner and earliest changed stage: NativeExportParser owns which allowance was exhausted (new structured tag); NativeExportsProvider is the only consumer and now derives recovery from the tag. The superseded blanket count mapping is removed.
  • Contribution scope fit and linked maintainer decision: ordinary fix; not applicable.
  • CLI and MCP/tool-catalog contract: no schema change. Only remediation.action text and the fixedAllowance name/kind differ for the byte refusal (and parser kind for the reader budget); code, retryable, message, and details.reported_limits are unchanged.
  • Provider, bridge, target-format, or platform compatibility: built-in PE/ELF reader only; no external engine.
  • Evidence, artifact, provenance, or reconstruction contract: none (failure path only; no Evidence is produced).
  • Target selection, authority, upstream behavior, and cleanup details: not applicable.
  • Generated metadata, package, or installation impact: none.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated:

    • src/native/exports/NativeExportParser.test.ts: the existing row-ceiling and retained-text refusals now assert NativeExportLimitFailure with limit: "rows" / "retained_text", the unchanged maximum_bytes, and message.
    • tests/boundary/filesystem/nativeExports.test.ts: the existing peRepeatedExportNamesImage case (4100 aliases of one 4096-byte name, as in the issue) now asserts through the service reportedLimits.maximum 16777216, retryable: false, fixedAllowance.kind: "bytes", and that analysisErrorRemediationAction contains "fixed byte allowance" and not "fixed count"; a new control with declaredFunctions: 0x40001 asserts maximum 262144, kind: "count", and the inverse wording. Boundary regression class: independent limits (byte budget vs entry count) and public error delivery.
  • Base reproduction or other evidence: source-derived — on main the provider branch returned fixedAllowanceOptions("The native export inventory allowance", "count") for every BinaryResourceFailure, so the new kind: "bytes" assertions fail there. Executed: the issue's Python reproduction against this branch's built CLI (output below).

  • User-visible CLI/MCP output: node scripts/rea.mjs inspect-native-exports names-4100.dll --format json (exit 1, empty stderr):

    {
      "code": "resource_constraint",
      "retryable": false,
      "message": "Selected artifact <target>: Export names exceed the 16777216-byte retained-text allowance",
      "remediation": {
        "action": "The 16777216-byte native export retained-text allowance is a fixed byte allowance. Waiting for an active analysis to finish does not raise it. Repeating the unchanged request fails the same way."
      },
      "details": {
        "resource": "capacity",
        "reported_limits": { "boundary": "structure", "maximum": 16777216 }
      }
    }

    The 4096-alias control still exits 0 with 4096 exports and complete coverage.

  • MCP delivery was exercised with real bounded PE fixtures for both retained-text bytes and entry count; the advertised tool returned the correct maximum, nonretryable status and unit-specific recovery. The parser kind for the shared reader budget is covered by the provider's existing type switch and typecheck only, not by a dedicated fixture.

  • Observed, derived, and inferred claims remain distinguishable.

  • Artifact identity, source provenance, and failed attempts remain preserved.

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

Validation performed

  • npm run test:local -- src/native/exports/NativeExportParser.test.ts — 41 passed.
  • npm run test:focused -- tests/boundary/filesystem/nativeExports.test.ts — 9 passed (includes the built runtime).
  • npm run test:focused -- tests/boundary/mcp/binaryDiagnosticsMcp.test.ts — 8 passed, including the two unit-specific allowance refusals through MCP.
  • npm run check:fast — typecheck and lint passed (also ran in the pre-push hook).
  • Issue reproduction script (built CLI, isolated HOME/XDG, Node v24.22.1) — 4096 names: exit 0, 4096 exports, complete coverage; 4100 names: exit 1, output above.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Error code, retryability, message, and reported limits are unchanged; only recovery wording and fixedAllowance name/kind differ.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable (built-in reader); executed on macOS arm64.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no new file, process, or network access.

Author readiness

Human owner: @ayobamiseun

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

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.

🤖 Generated with Claude Code

The native export parser throws one BinaryResourceFailure for both its
262144-entry inventory ceiling and its 16 MiB retained-text byte budget, and
NativeExportsProvider mapped every such refusal to the fixed-count recovery.
A PE whose export names exhaust the byte budget therefore reported
reported_limits.maximum 16777216 next to "is a fixed count".

Tag each parser allowance at the producing boundary (NativeExportLimitFailure
with limit "rows" or "retained_text") and let the provider select count,
byte, or structural-decoding recovery from that tag instead of from message
text. The refusal code, non-retryable flag, message, and reported maximum are
unchanged.
@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Low impact] The change affects recovery details for native export refusals.

The existing test-rule violation must be fixed before merging; no new blocking defect was found.

Findings

  1. P2 Harmless wording breaks tests ▶
Fix with agent prompt
### Issue 1
tests/boundary/filesystem/nativeExports.test.ts:95-96
These assertions require specific recovery wording and forbid the old phrase. This violates the repository directive to check structured facts and compare delivered guidance with its owning formatter instead of freezing explanatory text.

Keep the independent checks for `fixedAllowance.kind`, the maximum, and retryability, then compare the action with `fixedAllowanceRemediation`. Apply the same cleanup to the count control and the new message assertions in `NativeExportParser.test.ts`. This repository requirement must be satisfied before merging.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

The PR gives native export limit failures a structured tag and uses it to choose recovery guidance with the correct units.

  • Native export errors name the limit that stopped the parser.

Reviews (2) · Last reviewed commit: "test(native): verify export allowance re..." · Reviewed by Greptile

Comment on lines +95 to +96
expect(action).toContain("fixed byte allowance");
expect(action).not.toContain("fixed count");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Harmless wording breaks tests

These assertions require specific recovery wording and forbid the old phrase. This violates the repository directive to check structured facts and compare delivered guidance with its owning formatter instead of freezing explanatory text.

Keep the independent checks for fixedAllowance.kind, the maximum, and retryability, then compare the action with fixedAllowanceRemediation. Apply the same cleanup to the count control and the new message assertions in NativeExportParser.test.ts. This repository requirement must be satisfied before merging.

Context Used: AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/boundary/filesystem/nativeExports.test.ts
Line: 95-96

Comment:
**Harmless wording breaks tests**

These assertions require specific recovery wording and forbid the old phrase. This violates the repository directive to check structured facts and compare delivered guidance with its owning formatter instead of freezing explanatory text.

Keep the independent checks for `fixedAllowance.kind`, the maximum, and retryability, then compare the action with `fixedAllowanceRemediation`. Apply the same cleanup to the count control and the new message assertions in `NativeExportParser.test.ts`. This repository requirement must be satisfied before merging.

**Context Used:** AGENTS.md ([source](https://github.com/morluto/rea/blob/main/AGENTS.md))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@ayobamiseun
ayobamiseun marked this pull request as ready for review October 28, 2026 19:30
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 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-28T19:35:34.873978Z a831d30 Draft marked ready
ℹ️ 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.

@morluto

morluto commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Hey @ayobamiseun, thanks for this! The fix looks good. What's left: there is 1 unresolved review thread from Greptile, about "Harmless wording breaks tests". Greptile is at 4/5 on the current head, mainly over "Harmless wording breaks tests", so addressing that thread should bump it. Once that's done I'm happy to merge it.

gensokyo-dev added a commit that referenced this pull request Nov 14, 2026
The native export parser throws one BinaryResourceFailure for both its
262144-entry inventory ceiling and its 16 MiB retained-text byte budget, and
NativeExportsProvider mapped every such refusal to the fixed-count recovery.
A PE whose export names exhaust the byte budget therefore reported
reported_limits.maximum 16777216 next to "is a fixed count".

Tag each parser allowance at the producing boundary (NativeExportLimitFailure
with limit "rows" or "retained_text") and let the provider select count,
byte, or structural-decoding recovery from that tag instead of from message
text. The refusal code, non-retryable flag, message, and reported maximum are
unchanged.

Fixes #7628
Supersedes #7754

Co-Authored-By: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
gensokyo-dev added a commit that referenced this pull request Nov 14, 2026
The native export parser throws one BinaryResourceFailure for both its
262144-entry inventory ceiling and its 16 MiB retained-text byte budget, and
NativeExportsProvider mapped every such refusal to the fixed-count recovery.
A PE whose export names exhaust the byte budget therefore reported
reported_limits.maximum 16777216 next to "is a fixed count".

Tag each parser allowance at the producing boundary (NativeExportLimitFailure
with limit "rows" or "retained_text") and let the provider select count,
byte, or structural-decoding recovery from that tag instead of from message
text. The refusal code, non-retryable flag, message, and reported maximum are
unchanged.

Fixes #7628
Supersedes #7754

Co-Authored-By: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
N0zoM1z0 pushed a commit that referenced this pull request Nov 14, 2026
The native export parser throws one BinaryResourceFailure for both its
262144-entry inventory ceiling and its 16 MiB retained-text byte budget, and
NativeExportsProvider mapped every such refusal to the fixed-count recovery.
A PE whose export names exhaust the byte budget therefore reported
reported_limits.maximum 16777216 next to "is a fixed count".

Tag each parser allowance at the producing boundary (NativeExportLimitFailure
with limit "rows" or "retained_text") and let the provider select count,
byte, or structural-decoding recovery from that tag instead of from message
text. The refusal code, non-retryable flag, message, and reported maximum are
unchanged.

Fixes #7628
Supersedes #7754

Co-Authored-By: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
@N0zoM1z0

Copy link
Copy Markdown
Collaborator

Thank you for this fix. It landed in #10499 with your authorship kept on the commit (adapted where noted in the PR), so I'm closing this PR as superseded.

@N0zoM1z0 N0zoM1z0 closed this Nov 14, 2026
@morluto morluto added area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Native export byte-limit recovery describes the limit as a count

3 participants