Skip to content

fix(truncate): enforce VFS limits before resize#1616

Merged
chaliy merged 1 commit into
mainfrom
2026-05-08-fix-truncate-vfs-limit
May 8, 2026
Merged

fix(truncate): enforce VFS limits before resize#1616
chaliy merged 1 commit into
mainfrom
2026-05-08-fix-truncate-vfs-limit

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented May 8, 2026

What

Reject truncate target sizes that exceed the active VFS max_file_size/max_total_bytes before resizing the in-memory file buffer.

Why

truncate -s 4G /tmp/p previously passed the builtin's hard-coded 4 GiB check and attempted to allocate/zero-fill before write_file enforced default 10 MB VFS limits.

How

  • Replace the hard-coded truncate cap with ctx.fs.limits()-derived validation.
  • Use usize::try_from before allocation to avoid truncating oversized lengths on narrow platforms.
  • Add a regression test proving oversized targets fail before the write path.
  • Update TM-DOS-005 threat-model mitigation text.

Risk

  • Low
  • Could reject truncate requests above the configured VFS limit earlier than before; this matches VFS quota semantics and avoids allocation DoS.

Checklist

  • Tests added or updated
  • Backward compatibility considered

Verification

  • CARGO_BUILD_JOBS=1 cargo test -p bashkit --lib builtins::truncate::tests::rejects_target_above_vfs_limit_before_write --all-features failed before the fix with cannot write ... file too large, then passed after the fix.
  • CARGO_BUILD_JOBS=1 cargo test -p bashkit --lib builtins::truncate::tests --all-features
  • just pre-pr
  • cargo run -p bashkit-cli -- -c "truncate -s 4G /tmp/p; echo exit=\$?; test ! -e /tmp/p && echo no-file"

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

cloudflare-workers-and-pages Bot commented May 8, 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 cd5fc5a Commit Preview URL May 08 2026, 08:21 PM

@chaliy chaliy merged commit 14d9661 into main May 8, 2026
34 checks passed
@chaliy chaliy deleted the 2026-05-08-fix-truncate-vfs-limit branch May 8, 2026 20:32
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