Skip to content

feat(interp): add glob safety limits with unit tests and benchmarks#154

Merged
AlexandreYang merged 4 commits intomainfrom
alex/glob_test
Mar 25, 2026
Merged

feat(interp): add glob safety limits with unit tests and benchmarks#154
AlexandreYang merged 4 commits intomainfrom
alex/glob_test

Conversation

@AlexandreYang
Copy link
Copy Markdown
Member

@AlexandreYang AlexandreYang commented Mar 25, 2026

Summary

  • Add safety limits for shell globbing (maxGlobDirReads, maxGlobResults) to prevent pathological patterns from causing excessive resource usage via directory read counting
  • Add comprehensive benchmarks for glob expansion covering simple, nested, recursive, and pathological pattern types
  • Add unit tests for globReadDirCount limit internals verifying the counting mechanism and error propagation
  • Add scenario tests for pathological glob patterns (many stars, repeated star args, interspersed text)

Test plan

  • go test ./interp/ -run TestGlob -count=1
  • go test ./interp/ -run TestGlobReadDir -count=1
  • go test ./interp/ -bench BenchmarkGlob -benchtime=3s
  • go test ./tests/ -run TestShellScenarios -count=1
  • CI passes all checks

🤖 Generated with Claude Code

AlexandreYang and others added 3 commits March 25, 2026 20:19
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>
@AlexandreYang AlexandreYang marked this pull request as ready for review March 25, 2026 20:28
Comment thread interp/api.go
// across the entire Run() invocation. It is shared with subshells
// (including concurrent pipe subshells) via pointer, and must be
// accessed atomically.
globReadDirCount *atomic.Int64
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Doesn't actually matter, but surprised it didn't use a uint for this

Copy link
Copy Markdown
Member Author

@AlexandreYang AlexandreYang Mar 25, 2026

Choose a reason for hiding this comment

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

yeah, not sure why, maybe the LLM thinks it doesn't matter too :p

@AlexandreYang AlexandreYang changed the title feat(interp): add glob safety limits and benchmarks feat(interp): add glob safety limits with unit tests and benchmarks Mar 25, 2026
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>
Comment thread interp/runner_expand.go
// 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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this ratched down enough?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not sure, but we don't want to risk having something too low that will limit capabilities either.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

@AlexandreYang AlexandreYang added this pull request to the merge queue Mar 25, 2026
Merged via the queue into main with commit b88b205 Mar 25, 2026
34 of 35 checks passed
@AlexandreYang AlexandreYang deleted the alex/glob_test branch March 25, 2026 20:37
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 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: ""
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants