feat(interp): add glob safety limits with unit tests and benchmarks#154
feat(interp): add glob safety limits with unit tests and benchmarks#154AlexandreYang merged 4 commits intomainfrom
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| // across the entire Run() invocation. It is shared with subshells | ||
| // (including concurrent pipe subshells) via pointer, and must be | ||
| // accessed atomically. | ||
| globReadDirCount *atomic.Int64 |
There was a problem hiding this comment.
Doesn't actually matter, but surprised it didn't use a uint for this
There was a problem hiding this comment.
yeah, not sure why, maybe the LLM thinks it doesn't matter too :p
The glob safety limits feature added atomic.Int64 usage in interp/api.go but the symbol was not added to the interp allowed symbols list. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
| // allowed per Run() call. This prevents memory exhaustion from scripts that | ||
| // trigger an excessive number of glob expansions (e.g. millions of unquoted | ||
| // * tokens, or deeply nested glob patterns in loops). | ||
| const MaxGlobReadDirCalls = 10_000 |
There was a problem hiding this comment.
Is this ratched down enough?
There was a problem hiding this comment.
I'm not sure, but we don't want to risk having something too low that will limit capabilities either.
There was a problem hiding this comment.
In general I think we want to err on the side of lower memory usage, the LLM can always try again with a more scoped request if it hits limits
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 358507f94e
ℹ️ 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".
| expect: | ||
| stdout: |+ | ||
| bar foo | ||
| stderr: "" |
There was a problem hiding this comment.
Use
|+ block scalars for scenario stderr fields
The repository rule in AGENTS.md requires input.script, expect.stdout, and expect.stderr to always use YAML |+ block scalars, but this scenario uses stderr: "" (same issue appears in the other new globbing scenario files in this commit). This is a documented test-format requirement for this repo, so these cases should be converted to stderr: |+ to keep scenario definitions compliant and consistent.
Useful? React with 👍 / 👎.
Summary
maxGlobDirReads,maxGlobResults) to prevent pathological patterns from causing excessive resource usage via directory read countingglobReadDirCountlimit internals verifying the counting mechanism and error propagationTest plan
go test ./interp/ -run TestGlob -count=1go test ./interp/ -run TestGlobReadDir -count=1go test ./interp/ -bench BenchmarkGlob -benchtime=3sgo test ./tests/ -run TestShellScenarios -count=1🤖 Generated with Claude Code