Skip to content

fix(snapshot): account function source bytes#1837

Merged
chaliy merged 1 commit into
mainfrom
2026-06-02-propose-fix-for-memory-limits-bypass
Jun 2, 2026
Merged

fix(snapshot): account function source bytes#1837
chaliy merged 1 commit into
mainfrom
2026-06-02-propose-fix-for-memory-limits-bypass

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented Jun 2, 2026

Motivation

  • Prevent attacker-controlled trailing EOF comments from being retained in FunctionDef.source without charging against MemoryLimits::max_function_body_bytes, which allowed resource-exhaustion via many large function sources.

Description

  • Stop EOF source capture from returning input.len() by using current_span.end.offset at EOF in Parser::current_command_end_offset so skipped trailing comments aren't included in captured source (crates/bashkit/src/parser/mod.rs).
  • Add function_storage_bytes(func: &FunctionDef) to charge stored FunctionDef.source bytes when present and fall back to AST span size for legacy cases (crates/bashkit/src/interpreter/mod.rs).
  • Use function_storage_bytes when enforcing function insert/replace budgets at runtime and during snapshot restore and budget recompute so stored source is accounted for (crates/bashkit/src/interpreter/mod.rs).
  • Add integration tests that assert trailing EOF comments are not spuriously retained and that source-only snapshot restores are charged against max_function_body_bytes (crates/bashkit/tests/integration/snapshot_tests.rs).

Testing

  • Ran targeted unit/integration tests snapshot_function_source_excludes_trailing_eof_comment and snapshot_restore_counts_source_bytes_against_function_limit and both passed.
  • Ran the full snapshot integration test suite cargo test -p bashkit --test integration snapshot_tests:: and all snapshot tests passed (40 passed, 0 failed).
  • Ran cargo fmt --check and cargo clippy -p bashkit --tests -- -D warnings as formatting/lint checks and they succeeded.

Codex Task

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Jun 2, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bashkit 89bc3c0 Commit Preview URL Jun 02 2026, 09:35 AM

@chaliy chaliy force-pushed the 2026-06-02-propose-fix-for-memory-limits-bypass branch from 3bd038c to 89bc3c0 Compare June 2, 2026 09:19
@chaliy chaliy merged commit 9566ac1 into main Jun 2, 2026
34 checks passed
@chaliy chaliy deleted the 2026-06-02-propose-fix-for-memory-limits-bypass branch June 2, 2026 13:29
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.

1 participant