Skip to content

fix(contrib): bound memory and run time of embedded interpreters - #873

Merged
ewhauser merged 6 commits into
mainfrom
claude/fix-contrib-review-f25758
Oct 19, 2026
Merged

ewhauser merged 6 commits into
mainfrom
claude/fix-contrib-review-f25758

Conversation

@ewhauser

Copy link
Copy Markdown
Owner

Fixes the verified contrib/ findings from the security and bug review of main at 83b31f1. Changes stay in contrib/ plus SPEC.md.

What changed

python (HIGH)

  • Without a request deadline, the REPL now gets the 60s pythonDefaultMaxDuration. Before, it ran with no limit.
  • On cancel, python returns control right away (exit 130/124), even if Monty keeps spinning. The abandoned run can't write to stdout or the filesystem, and it winds down under its own time limit.
  • $TTY only selects the REPL when it names a live sandbox terminal (a char device for this execution). So printf 'while True: pass\n' | TTY=/dev/tty python3 now runs stdin as a script.

jq (HIGH): changes in the vendored gojq fork, contrib/jq/internal/gojq/size.go

  • Strings built by repeat, concat, join, tojson/tostring and @csv/@tsv/@sh are capped at 64 MiB.
  • Arrays built by collect (including [range(n)]), concat, flatten, split and explode are capped at 4Mi elements.
  • Hitting a cap is exit 5 with an exceeds size limit error that try cannot catch.
  • Each filter evaluation gets a 60s fallback when the request has no deadline (repeat(.), def f: f; f).

nodejs (HIGH, MEDIUM)

  • Size caps that throw a catchable RangeError:
    • over 64 MiB: repeat, padStart/padEnd, ArrayBuffer, typed arrays, Buffer.alloc/from/concat
    • over 16Mi elements: Array, Array.from, split, Array.prototype methods
  • The wrappers share the original prototype, so instanceof, subclassing and inherited statics keep working. goja's instanceof rejects Proxy-wrapped constructors, so Proxies were not an option.
  • A watchdog interrupts the VM after 1 GiB of heap growth (confirmed after a forced GC) or after the 60s fallback.
  • fs option reads go through an optionValue helper that maps missing keys to undefined. mkdirSync(p,{recursive:true}), rmSync(p,{force:true}), readFileSync(p,{}), readdirSync(d,{}) and the others no longer panic the shell.
  • mkdirSync modes keep only the 0o7777 bits (setuid/setgid/sticky are mapped properly), and negative, fractional or infinite modes are rejected. {mode: 134217728+493} no longer sets ModeSymlink. A numeric second argument (mkdirSync(p, 0o750)) is now honored.

awk, sqlite3 (LOW)

  • awk: without a request deadline, a program gets 60s of run time. The clock pauses while awk reads stdin or waits on system(), so a slow upstream producer doesn't count. Exceeding it is exit 2.
  • sqlite3: without a request deadline, SQL execution gets a 60s fallback that starts after stdin is read (infinite WITH RECURSIVE). Exceeding it is exit 1.

codingtools

  • Image reads are capped at MaxImageBytes (5 MiB).

Reviewer notes

  • Python in interactive sessions: inside Session.Interact, a shell pipe and the session's own terminal input both reach commands as the same virtual pipe type. So printf … | python3 typed in an interactive session still opens the REPL, though it is now bounded and stops promptly on cancel. Fixing that fully needs the interp layer to mark pipeline pipes.
  • jq aggregate memory: jq's caps limit each value. A program that holds many capped values at once is not yet bounded by a total budget; SPEC.md records this. I tried a process-wide heap watchdog and dropped it, because concurrent evaluations tripped it (the parallel depth tests did).
  • nodejs watchdog scope: goja has no per-runtime allocation accounting, so the nodejs watchdog measures the whole process. Heavy concurrent work in the same process counts against the budget. Its regression test is non-parallel.
  • Pre-existing test failure: TestNodeJSShebangViaEnvWorks was already failing on main. It ran a 0644 script, and the runtime now enforces the exec bit. The test now runs chmod +x first.
  • SPEC.md is updated for the python, jq, nodejs, awk and sqlite3 limits. The python, nodejs and codingtools READMEs and the gojq fork README are updated too.

Testing

  • Each finding has a regression test: python_limits_test.go, jq_limits_test.go, nodejs limits_test.go/modules_test.go, awk_limits_test.go, sqlite3_limits_test.go, toolset_test.go.
  • go test ./... passes in contrib/python, jq, nodejs, awk, sqlite3 and codingtools.
  • golangci-lint (custom-gcl) reports 0 issues for the root and each touched module. It was run with --allow-parallel-runners because other sessions held the lint lock.

@ewhauser
ewhauser merged commit 3da5d0a into main Oct 19, 2026
17 checks passed
@ewhauser
ewhauser deleted the claude/fix-contrib-review-f25758 branch October 19, 2026 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant