Skip to content

fix(pwntools): let callers widen the artifact input bound - #2486

Merged
morluto merged 3 commits into
morluto:mainfrom
NIU-123370:fix/pwntools-input-bound-override
Oct 13, 2026
Merged

morluto merged 3 commits into
morluto:mainfrom
NIU-123370:fix/pwntools-input-bound-override

Conversation

@NIU-123370

Copy link
Copy Markdown
Contributor

Summary

The pwntools adapters rejected every artifact above 32 MiB before any analysis ran, and no configuration surface could raise that bound, so ordinary recorded core dumps (the report's own 165 MiB example) were unanalyzable.

This adds REA_PWNTOOLS_MAX_INPUT_BYTES in front of the shipped default, which is the first option in #2446 — the default stays at 32 MiB so the existing protection is not weakened for anyone who does not opt in.

Fixes #2446

What changed

  • src/native/pwntools/PwntoolsInputLimit.ts (new) — one owner for the bound. undefined keeps PWNTOOLS_LIMITS.inputBytes; anything else must be a decimal integer from 1 to 1073741824. The ceiling is tied to the child's existing 3 GiB address-space reservation: the artifact is read into one in-memory buffer and staged again as a private snapshot, so one third of that reservation is the widest bound that still leaves the decoder room.
  • src/native/pwntools/PwntoolsDecoder.ts — resolves the bound from the adapter's own environment, after the existing REA_PWNTOOLS_PYTHON validation and before the artifact is read, then passes it to readStableArtifact. An unusable value is refused as provider_unavailable with the constraint text instead of silently falling back to the default. The other budgets (outputBytes, timeoutMs, diagnosticBytes) are untouched.
  • docs/recorded-crashes.md, docs/binary-diagnostics.md — the two places that stated the 32 MiB input bound now say it is raisable and what stays fixed.

What this deliberately does not do

Raising the input bound alone does not raise the reply, diagnostic or deadline budgets, so a core that needs more than 64 MiB of reply or 30 s of decoder time now fails at the decoder stage rather than at admission. That is the interaction #2446 describes. I kept the reply/deadline knobs out of this change because widening them is a different decision (it changes what the owned bridge may consume); if you want them configurable too, the same resolver shape extends to them directly.

Verification

src/native/pwntools/PwntoolsInputLimit.test.ts (18 cases, runs on any host) pins: the shipped default and its 32 MiB value; accepted values 1, 64 MiB, the report's 172879872, and the ceiling; and rejection of "", 0, -1, 33554432.0, 1e8, a leading space, 67_108_864, 0x2000000, one above the ceiling, and an integer beyond Number.MAX_SAFE_INTEGER.

tests/boundary/binaryDiagnostics/pwntoolsInputBoundAdmission.test.ts (3 cases) drives PwntoolsLayoutProvider with a 33,554,433-byte sparse regular file and asserts the projected caller-visible failure:

Case Projected result
no override invalid_request, detail contains Selected artifact exceeds 33554432 bytes
REA_PWNTOOLS_MAX_INPUT_BYTES=33554433 unreadable_output with the owned process's no reply captured — admission passed and the bridge really ran
REA_PWNTOOLS_MAX_INPUT_BYTES=0 provider_unavailable, detail contains the constraint, and no artifact-size text — refused before reading

Read this before reviewing those three cases: they are gated with it.runIf(!unsupportedHost) because the adapter itself refuses non-Linux/x64 hosts before reaching admission. I am on macOS, so to prove the wiring and the mutants I temporarily (a) commented out the adapter's host check and (b) flipped the test's unsupportedHost to false, ran the cases, then reverted both — the committed files contain the original gate and no bypass. On Linux/x64 they run unchanged; if they fail there I will fix them in this PR.

Mutation arms, each run, each killed by exactly one case:

Arm Killed by
read bound ignored (inputLimit.bytes → default) the widened-override admission case
override validation deleted the unusable-override admission case
default widened to 64 MiB the shipped-default case
regex dropped so any string parses 7 rejection cases
ceiling removed from the schema 2 rejection cases
empty string treated as unset the "" rejection case

Static gates on the rebased commit: tsc --noEmit clean; oxfmt --check clean; npx knip clean; oxlint 0 errors with 3 warnings that are byte-identical to the same file on untouched origin/main; vitest --project adapters 171 files / 1981 tests passed, 4 skipped.

Known collision surface

src/native/pwntools/PwntoolsDecoder.ts is also touched by #2281, #2282, #2284 and #2436. My edit there is one import, one validation block inserted before phase = "artifact-read", and one argument change, all inside the same guard sequence, so it should rebase cleanly; I will rebase again if it lands first.

docs/binary-diagnostics.md is touched by #2331 — a two-sentence prose edit.

Base: 2c7240cf. Head: 1 commit, 6 files.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

The pwntools adapters rejected every artifact over 32 MiB before any
analysis ran, and nothing in configuration, environment, CLI or MCP
could raise that bound, so real recorded core dumps stayed unanalyzable.

Resolve the bound from REA_PWNTOOLS_MAX_INPUT_BYTES in front of the
shipped default. An absent value keeps 32 MiB, and a value outside
1..1073741824 bytes is refused as unusable provider configuration before
the artifact is read instead of falling back silently.
@CassieFox23

CassieFox23 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: The fix works on Linux x64. All 21 tests from this PR pass on Node 22, 24 and 26, and the 3 admission cases ran. A real core dump now opens through the CLI when the variable is set.

Thanks, NIU-123370, for the clear write-up and the mutation table. You asked for a Linux run, so here it is.

Results

Check Node 22.23.1 Node 24.18.0 Node 26.11.1
18 unit cases, head pass pass pass
3 admission cases, head pass pass pass

On head, none of the 3 admission cases were skipped. On base bb54082, I copied in your two test files. The unit file cannot import the new module. Admission case 1 passes and cases 2 and 3 fail, as expected.

Through the CLI, with real pwntools 4.15.0 on Node 24:

File and variable base head
20 MiB ELF, unset layout layout
32 MiB plus 1 byte, unset refused refused
32 MiB plus 1 byte, set to its size refused layout
100 MiB ELF, set to its size refused layout
100 MiB ELF, set 1 byte short refused refused
1 GiB ELF, set to 1 GiB not run layout, 2.3 GB peak
9 bad values, such as 0 or 1e8 ignored refused, names the variable

Base refuses with invalid_request. Head gives provider_unavailable for a bad value. A real core dump of 64,883,376 bytes (62 MiB, made with gdb) is refused on base. On head, inspect-recorded-crash returns a report when the variable equals the size.

Two small notes. The line in docs/recorded-crashes.md says a bad value gives an invalid request, but head gives provider_unavailable. The message for a bad value still says to run rea doctor.

Not run

  • The 64 MiB reply bound and the 30-second deadline (no run reached them).
  • The MCP tools (CLI only).
  • Your mutation arms, tsc, oxlint and knip.
  • Node 22 and 26 on base.
  • macOS.
Commands
REA_PWNTOOLS_PYTHON=~/.local/opt/pwntools-4.15.0/bin/python \
REA_PWNTOOLS_MAX_INPUT_BYTES=<value> \
node scripts/rea.mjs inspect-binary-layout <file> --format json
node scripts/run-development-tests.mjs focused \
  src/native/pwntools/PwntoolsInputLimit.test.ts \
  tests/boundary/binaryDiagnostics/pwntoolsInputBoundAdmission.test.ts

I built the ELF files from a small system ELF and extended each with truncate. There were 41 cases per side per command, and I read every exit code.

Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
  • CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
  • RAM: 32 GB DDR4-3600
  • Node: 22.23.1, 24.18.0, 26.11.1
  • Head: 848082f. Base: bb54082.
  • Other: pwntools 4.15.0, pyelftools 0.33, Unicorn 2.1.2. Another test agent shared the box, so timings are rough.

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

@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

@greptileai review

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable new issue was found.

Summary

Adds REA_PWNTOOLS_MAX_INPUT_BYTES to both pwntools adapters while keeping the 32 MiB default.

  • Pwntools callers can raise the artifact input limit.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Validate caller-selected Python] --> B[Resolve input bound]
  B -->|Invalid setting| C[provider_unavailable]
  B -->|Absent setting| D[Use 32 MiB]
  B -->|Valid setting| E[Use configured bound up to 1 GiB]
  D --> F[Read stable artifact]
  E --> F
  F --> G[Stage private snapshot]
  G --> H[Run decoder with unchanged budgets]
Loading

Reviews (3) · Last reviewed commit: "chore: merge upstream CI baseline fixes" · Reviewed by Greptile

Comment thread src/native/pwntools/PwntoolsDecoder.ts Resolved
Comment thread docs/recorded-crashes.md Resolved
An unusable REA_PWNTOOLS_MAX_INPUT_BYTES travelled through the shared
engine-absence helper, which always stamped configuration_key
REA_PWNTOOLS_PYTHON, so a caller following that field was pointed at the
Python executable instead of the bound it had just set. The guide also
described the refusal as an invalid request while the decoder reports
provider_unavailable.

Let the failure context carry the key under review and pass the bound's
own name at that call site, then state the code callers actually receive
in the guide. Assert the key on the projected rejection so the engine
default and the bound override each stay attributed to the right setting.
@NIU-123370

Copy link
Copy Markdown
Contributor Author

Both P2 findings are addressed in 5bb5de7.

  • Error names the wrong setting. PwntoolsFailureContext now carries the key under review (PwntoolsFailures.ts:33), the helper reads it with the previous constant as its fallback (PwntoolsFailures.ts:278), and only the bound call site passes REA_PWNTOOLS_MAX_INPUT_BYTES (PwntoolsDecoder.ts:244-253). Every other provider_unavailable path keeps reporting REA_PWNTOOLS_PYTHON.
  • Guide gives the wrong error. docs/recorded-crashes.md:76 now says provider_unavailable, which is what the decoder returns and what the boundary test expects.

Guards added so neither side can drift back silently:

  • pwntoolsInputBoundAdmission.test.ts case 3 asserts details.rejections[0].diagnostics.configuration_key.
  • PwntoolsInputLimit.test.ts adds one case that pins both directions: the helper default stays REA_PWNTOOLS_PYTHON, and the bound appears only when the context overrides it.

Verification on this box (macOS, Node 26.11.1): tsc --noEmit, knip, oxfmt --check, docs:check, scan:todos and jscpd (2.98% duplicated) are clean, oxlint reports 0 errors with 12 warnings none of which land on the changed lines, and the 19 unit cases pass.

The three admission cases are runIf Linux x64, so they skip here. I temporarily disabled the host check in PwntoolsDecoder.ts and the runIf in that test file to run them on this machine: 3/3 pass on the fixed tree. Three mutations, each reverted afterwards:

Mutation Result
call site passes the plain context again admission case 3 fails, only on configuration_key (REA_PWNTOOLS_MAX_INPUT_BYTES expected, REA_PWNTOOLS_PYTHON received); the other two cases still pass
helper ignores the context key 2 of 22 fail: admission case 3 and the new unit case
helper fallback renamed the new unit case fails on its default assertion, 1 of 19

Both temporary edits were reverted before committing and the pushed tree contains no gate changes; grep for the temporary switch returns nothing. CI still has the Linux runs as the authority for these three cases.

One note left as is on purpose: the run rea doctor wording @CassieFox23 saw comes from the shared providerSelectionUserMessage for every provider_unavailable in src/domain/providerSelectionError.ts:82, so changing it would also change Hopper and the other providers. I did not want to widen this PR for that.

@NIU-123370

Copy link
Copy Markdown
Contributor Author

The Static checks failure is not this branch

The step that exits 1 is npm run jscpd (threshold 3.0% in .jscpd.json). Measured on this box against three trees:

Tree Scanned files Clones Duplicated lines npm run jscpd
bb540826 — this PR's base 2321 1427 2.98% exit 0
20f51d72 — main when this push was checked 2361 1475 3.01% exit 1
b1e17363 — refs/pull/2486/merge 2364 1475 3.01% exit 1

The merge tree and current main report the same clone count, so the two commits here add none of it; main crossed 3.0% on its own. 4276aaf1 is 1474 clones / exit 1 on that same check, and the main run for it had already concluded failure at 06:58Z, before this push. Rebasing onto current main would inherit the identical number, so I did not rebase to chase this red.

The other checks in the CI range are green locally on 5bb5de73: tsc --noEmit, knip, oxfmt --check, oxlint (0 errors), docs:check, scan:todos, and the 19 pwntools unit cases. The three Linux-only admission cases passed with the host gate temporarily disabled, as described above.

@morluto
morluto merged commit c44d17f into morluto:main Oct 13, 2026
29 checks passed
@morluto morluto added bug Something isn't working area: evidence Evidence, artifacts, and reconstruction labels Oct 14, 2026
@morluto morluto added the provider: pwntools Analysis provider / engine: pwntools label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: evidence Evidence, artifacts, and reconstruction bug Something isn't working provider: pwntools Analysis provider / engine: pwntools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] pwntools provider rejects artifacts over a hardcoded 32 MiB inputBytes limit

3 participants