Skip to content

fix(native): raise default PE resource entry budget to 16384 - #1703

Merged
morluto merged 1 commit into
morluto:mainfrom
JasonBuildAI:fix/pe-resource-entry-budget-a7f3c9
Oct 11, 2026
Merged

morluto merged 1 commit into
morluto:mainfrom
JasonBuildAI:fix/pe-resource-entry-budget-a7f3c9

Conversation

@JasonBuildAI

Copy link
Copy Markdown
Contributor

Summary

Windows reverse engineers can now inspect stock Windows resource images such as imageres.dll.mun through the default CLI and MCP calls. Fixes #1702.

Before this change, rea inspect-pe-resources "C:\Windows\SystemResources\imageres.dll.mun" exited 1 with resource_constraint and returned no inventory, because the default max_entries budget (4096) is smaller than the largest stock tables (imageres 6476, shell32 5903, wmploc 5440 examined entries on Windows 11 25H2). After the change, the default budgets return coverage.status: "complete" with the full inventory.

Problem and expected behavior

Smallest trigger: run rea inspect-pe-resources with default budgets on any stock Windows resource image whose table exceeds 4096 examined entries.

Observed (base 13e03e9, real files):

$ rea inspect-pe-resources "C:\Windows\SystemResources\imageres.dll.mun" --format json; echo $?
{"code":"resource_constraint","category":"resource_constraint","message":"PE resource directory entry budget exceeded; no partial inventory was returned.","retryable":false,"details":{"operation":"inspect_pe_resources","resource":"memory","reason":"PE resource directory entry budget exceeded; no partial inventory was returned.","reported_limits":{"max_file_bytes":67108864,"max_entries":4096}}}
1

Expected: a complete inventory, confirmed independently by pefile 2024.8.26, which matches the parser exactly (0 mismatches across type/name/language, RVA, file offset, size, and code page) when the budget is raised.

Change and scope

  • src/domain/native/peResources.ts: default max_entries 4096 -> 16384, with the measured stock-image sizes cited at the default. The 65536 maximum and the independent 8 MiB metadata budget are unchanged, and exceeding any budget still fails closed without partial results.
  • src/native/pe/PeResources.fixture.ts: optional sectionBytes parameter so tests can emit larger tables through the same fixture.
  • tests/boundary/filesystem/peResources.test.ts: new test emits a 6476-entry table (two types, 1620 + 1617 single-language names) via a 256 KiB section and asserts the default budgets report complete coverage with 6476 examined entries and 3237 resources.
  • docs/binary-diagnostics.md: documents the new default with its basis.

Intentionally not included: changes to the parser, budgets, or error taxonomy; no new flags or tools.

Contract and boundary impact

  • Semantic owner and earliest changed stage: the input contract's default budget in src/domain/native/peResources.ts; the earliest changed stage is native-analysis budget admission. The CLI derives its default from the schema shape, so no CLI-local edit was needed.
  • CLI and MCP/tool-catalog contract: the advertised default for --max-entries / inspect_pe_resources.max_entries moves 4096 -> 16384; minimum 1 and maximum 65536 are unchanged. Callers that pass an explicit budget see identical behavior. Raising a default only admits calls that previously failed with a typed error, so this is not a breaking change.
  • Provider, bridge, target-format, or platform compatibility: parser and provider code untouched; no platform-specific paths.
  • Evidence, artifact, provenance, or reconstruction contract: coverage and inventory semantics unchanged; the bounded-failure mode (no partial inventory) is preserved and still covered by existing tests.
  • Process execution, authorization, cleanup, or containment impact: none. Allocation stays bounded by the 8 MiB metadata budget and the 65536 hard entry maximum.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none committed; .cache/mcp-tool-catalog.json was regenerated locally so the MCP schema-validity suite exercises the new default. docs/binary-diagnostics.md is the only authored doc change.

Evidence and regression coverage

  • Tests added or updated: tests/boundary/filesystem/peResources.test.ts (new stock-scale default-budget test) and the fixture's optional section size; parser and service suites still pass.
  • Base reproduction or other evidence: compiled-CLI runs against real stock images at base 13e03e9 fail with max_entries: 4096, and at head bfac8ac6 return complete coverage (raw output below). pefile counts agree exactly.
  • User-visible CLI/MCP output (if applicable):
# head, default budgets
$ rea inspect-pe-resources "C:\Windows\SystemResources\imageres.dll.mun" --format json
... "coverage":{"status":"complete","examined_entries":6476,"resources":3234} ...
$ rea inspect-pe-resources "C:\Windows\SystemResources\shell32.dll.mun" --format json
... "coverage":{"status":"complete","examined_entries":5903,"resources":2944} ...
$ rea inspect-pe-resources "C:\Windows\SystemResources\wmploc.DLL.mun" --format json
... "coverage":{"status":"complete","examined_entries":5440,"resources":2714} ...
# control, identical before and after: notepad.exe 69 examined entries / 31 resources
  • Remaining proof gaps: only Windows 11 25H2 (build 26200.9457) was measured; other Windows builds and non-English .mui tables were not above the old default in local scans (0 of 4286 System32 files, 0 of 1918 .mui files, 3 of 140 SystemResources files), so they are not exercised here. The repository's symlink boundary test fails on this machine with EPERM because Windows symlink creation needs developer mode; the same failure occurs on the unmodified base and is unrelated.

For evidence-bearing changes:

  • 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

  • node node_modules/vitest/vitest.mjs run tests/boundary/filesystem/peResources.test.ts src/native/pe/PeResourceParser.test.ts src/application/binaryDiagnostics/PeResourcesService.test.ts — 31 passed, 1 failed; the failure is the pre-existing EPERM symlink case, reproduced identically on base 13e03e9; the new stock-scale test passes.
  • npm run artifacts:mcp-catalog && node node_modules/vitest/vitest.mjs run tests/boundary/mcp/toolSchemaValidity.test.ts — 7 passed; the regenerated advertised schema carries "default": 16384.
  • npm run check:fast — 2 tasks successful (typecheck, lint).
  • npm run docs:check — 6 tasks successful.
  • pefile 2024.8.26 cross-check on the three stock images at --max-entries 65536 — 0 mismatches, identical resource counts (3234 / 2944 / 2714).
  • npx oxfmt --check on the changed files — reports only CRLF-vs-LF checkout differences caused by this Windows worktree; LF copies pass, and the committed blobs are LF.
  • rea inspect-pe-resources <file> --format json on base 13e03e9 and head bfac8ac6 — raw before/after output quoted above.

AI disclosure: this change was drafted with AI assistance at my request, under my direction and review.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Raising the default only admits calls that previously returned a typed resource_constraint failure; explicit budgets behave identically, and the failure mode for genuinely oversized inputs is unchanged.
  • Real Hopper/Ghidra, browser, or OS coverage: real Windows 11 25H2 stock resource images were analyzed through the compiled CLI; no provider (Hopper/Ghidra) involvement.
  • Package or release metadata impact: none; docs-only plus contract-default change.
  • Security, privacy, process, or containment review: no new inputs or privileges; allocation remains bounded by the existing budgets and fails closed.

Review checklist

  • This PR addresses a concrete problem or an agreed enhancement.
  • 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.

inspect-pe-resources rejected stock Windows resource images because their
tables exceed the 4096-entry default. Windows 11 25H2 SystemResources
measures imageres.dll.mun at 6476 examined entries, shell32.dll.mun at 5903
and wmploc.DLL.mun at 5440, so the default budget now admits each of them
with headroom while the maximum stays 65536. The independent 8 MiB metadata
budget still bounds allocation, and exceeding any budget still fails without
partial results.

The stable filesystem boundary test now emits a 6476-entry table through a
larger fixture section and asserts that the default budgets report complete
coverage, covering stock-image scale without a real Windows file.
@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-11T05:03:54.799093Z bfac8ac PR opened
ℹ️ 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.

JasonBuildAI added a commit to JasonBuildAI/rea that referenced this pull request Oct 11, 2026
@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: The fix works. Tables with 4,097 to 16,384 entries now load by default, and 16,385 is still refused with the same message. I found no regression, but two other size caps now matter more, and they are listed below.

I tested head bfac8ac against its base 13e03e9 (#1694) on Linux. I also applied the patch to current main 092de8f (#1716). It applied cleanly with patch -p1, and I tested that too.

Results

The PR's three test files pass on Node 22, 24 and 26. The new test fails on base, as it should. The table is in the first fold.

I built PE files with a known number of directory entries (type, name and language entries added up). I ran rea inspect-pe-resources on each tree, Node 24:

Entries (resources) Base Head Main plus patch
4,095 (2,047) complete complete complete
4,096 (2,048) complete complete complete
4,097 (2,048) refused, limit 4,096 complete complete
16,383 (8,191) refused, limit 4,096 complete complete
16,384 (8,192) refused, limit 4,096 complete complete
16,385 (8,192) refused, limit 4,096 refused, limit 16,384 refused, limit 16,384
20,001 (10,000) refused, limit 4,096 refused, limit 16,384 refused, limit 16,384

Each refusal gives the same message and exit code 1, with no partial results. On each accepted file, the counts match the real counts. The MCP tool inspect_pe_resources has the same cut-offs.

Issue 1702: its counting rule is right. Three tables with its exact counts are refused on base and complete on head. A real file, shell32.dll from Wine 11.17 Staging (LGPL-2.1-or-later), does the same. Details are in the Issue 1702 fold.

Two other caps now decide what fits. On base, the entry limit stopped these files first. So at defaults only the message changes. This is not a regression.

  • The 8 MiB metadata cap. A table with 8,191 names of 100 characters each passes the entry check and is then refused.
  • The MCP reply size cap. A table with 16,382 resources is complete on the CLI. MCP refuses it. The numbers are in a fold below.

Not run

  • The real Windows images named in the issue. I used same-size synthetic files and one Wine file.
  • A pefile cross-check on a directory with over 4,096 entries. pefile stops there. So my pefile checks used spread-out shapes.
  • The full test suite, typecheck, lint, docs:check and oxfmt.
  • The MCP tool and the full file matrix on Node 22 and 26. Only the CLI spot checks above ran there.
  • Other Windows builds, and resource files in other languages.

Thanks, JasonBuildAI, for the clear issue and the exact counts.

Test files

The PR's three test files (the changed one, the parser test and the service test):

Check Node 22.23.1 Node 24.18.0 Node 26.11.1
Head, 3 files 32 passed 32 passed 32 passed
Base, same 3 files (31 tests, no new one) not run 31 passed not run
Main plus patch, same 3 files not run 32 passed not run
New test copied onto base source not run fails: "entry budget exceeded" not run
MCP tool-schema test on head not run 7 passed not run
  • The PR text says one test fails on Windows (symlink permission). On this Linux box nothing failed.
  • Node 22 and 26 gave the same CLI answers on the files I repeated there.
  • The MCP tool advertises a max_entries default of 4,096 on base and 16,384 on head.
Issue 1702 check
  • I built three tables with the counts it reports (6,476 entries and 3,234 resources; 5,903 and 2,944; 5,440 and 2,714). Base refuses all three. Head and main plus patch return them whole. The counts match. pefile 2024.8.26 (MIT) finds the same resources. It shows 0 mismatches. These are synthetic files, not the Windows images.
  • A real file: shell32.dll from Wine 11.17 Staging. It has 5,206 entries and 3,086 resources. Base refuses it. Head and main plus patch return it whole. pefile finds the same 3,086 resources, with 0 mismatches.
    • Source: a Fedora Copr package from the user gloriouseggroll. Its name is wine-staging, version 11.17-1.
    • There is no download link.
    • sha256: e0be4d8f8c02a62bcd9089412c6fdce107ac566ebf88c90b04451e6892f4c552
    • Wine is LGPL-2.1-or-later, per its LICENSE file at tag wine-11.17.
    • Wine Staging says LGPLv2.1 in its LICENSE.md at tag v11.17, with a list of exceptions. I did not read the exceptions.
  • "The default is the only limiter" holds up to 16,384 entries. Past that, the two caps above apply.
Numbers for the two other caps
  • I raised the budget to 65,536 on head. The biggest table accepted had 28,995 entries (14,497 resources). With many languages it was 19,545 entries (19,543 resources). So 65,536 is not reachable.
  • A table with 8,191 names of 100 characters each has 16,383 entries. Base refuses it on the entry limit. Head refuses it on the metadata cap.
  • A table with 16,384 entries and 16,382 resources (many languages under one name) is complete on the CLI. MCP fails with a "stdio response budget" error. The largest such table MCP returned had 11,393 resources. The docs already warn about this buffer.
  • A table with 8,192 resources and 16,384 entries is fine over MCP.
  • A tree of shared directories that expands to 16 million entries is refused on both. Trees of the wrong depth fail with the same format error on both.
Time and memory

The box was shared (load average about 10 of 24 threads). CLI time includes about 1 s of startup. Each row is 3 to 5 runs, Node 24.

File Build Time Peak memory
9 entries head 1.04 to 1.12 s 311 to 323 MB
16,384 entries, 8,192 resources head, default 1.60 to 1.78 s 367 to 370 MB
same file base, --max-entries 65536 1.78 to 1.80 s 364 to 370 MB
16,384 entries, 16,382 resources head, default 1.94 to 2.11 s 383 to 389 MB
28,995 entries, 14,497 resources head, --max-entries 65536 2.02 to 2.19 s 394 to 470 MB

Changing the default costs nothing by itself. It only moves the gate.

Exact messages
CLI and MCP, entry limit (limit 4,096 on base, 16,384 on head):
PE resource directory entry budget exceeded; no partial inventory was returned.

Metadata cap:
PE resource metadata exceeds the 8 MiB complete-result allocation budget.

MCP only, response too large (16,382 resources, many languages):
The operation completed, but its complete MCP response exceeds the stdio response budget. The analysis result was not truncated.
Commands
# build each tree under /tmp (Node 24)
npm ci && npm run build && npm run test:prepare
# patch on main
patch -p1 < pr.patch
# the PR's tests, per Node
node node_modules/vitest/vitest.mjs run tests/boundary/filesystem/peResources.test.ts \
  src/native/pe/PeResourceParser.test.ts src/application/binaryDiagnostics/PeResourcesService.test.ts
# CLI, per file and tree
node scripts/rea.mjs inspect-pe-resources FILE --format json [--max-entries 65536]
# MCP: node scripts/rea.mjs --mcp, then tools/list and tools/call inspect_pe_resources

PE files were written by a stdlib Python script that lays out one .rsrc section. pefile ran in a throwaway venv.

Test setup

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

@JasonBuildAI

Copy link
Copy Markdown
Contributor Author

Thanks, @CassieFox23 — this is a thorough and very helpful independent verification. Confirming the two notes:

Both caps are pre-existing, unchanged by this PR, and already documented:

  • The 8 MiB metadata budget lives in the parser (src/native/pe/PeResourceParser.ts) and is independent of max_entries; it fails closed with no partial results. docs/binary-diagnostics.md documents it.
  • The MCP stdio response budget is a transport limit (src/config/mcpResponseBudget.ts, src/server/toolResult.ts), documented in docs/mcp-contracts.md and docs/binary-diagnostics.md (caller-configured receive buffer). The CLI remains the complete-output path.

The shapes this PR targets sit well inside both: the largest measured real file (imageres.dll.mun) is 6,476 entries / 3,234 resources and returns complete at default budgets, and your MCP ceiling of 11,393 resources is roughly 3.5x that. So no change is needed here; those caps only decide synthetic or much larger tables, and they preserve the existing fail-closed semantics.

The evidence also complements well: I measured the real Windows 11 25H2 SystemResources files on Windows, and you reproduced the same counts with same-size synthetic tables plus a real Wine 11.17 shell32.dll, with 0 pefile mismatches on both sides — which covers the real-Windows-file gap in your "Not run" list. Author-side validation additionally includes check:fast (typecheck + lint) and docs:check; the only failing case is the pre-existing Windows symlink EPERM, which reproduces on base. Agreed no rebase is needed since the patch applies cleanly to current main.

Leaving the PR as-is for maintainer review. Thanks again for the Linux and Node 22/24/26 coverage.

@morluto
morluto merged commit 951c2aa into morluto:main Oct 11, 2026
2 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 11, 2026
3 tasks done
@morluto

morluto commented Oct 11, 2026

Copy link
Copy Markdown
Owner

Welcome to REA, @JasonBuildAI! Thank you for checking the limit against actual Windows system files and cross-checking with pefile. That made the fix easy to assess, and imageres.dll.mun can now be inspected with the default settings.

@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 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] inspect-pe-resources rejects stock Windows resource images at the default entry budget

3 participants