Skip to content

fix(command-runner): grow command string buffer instead of assuming capacity - #29

Open
ratazzi wants to merge 1 commit into
masterfrom
fix/command-runner-overflow
Open

fix(command-runner): grow command string buffer instead of assuming capacity#29
ratazzi wants to merge 1 commit into
masterfrom
fix/command-runner-overflow

Conversation

@ratazzi

@ratazzi ratazzi commented Jul 16, 2026

Copy link
Copy Markdown
Owner

Problem

executeCommandWithLogging built its display/logging command string with appendAssumeCapacity/appendSliceAssumeCapacity on a buffer allocated with initCapacity(allocator, 256) (falling back to capacity 0 on allocation failure). The AssumeCapacity variants never grow the buffer, so any argv longer than 256 bytes wrote out of bounds.

This triggers on routine paths: apt_bootstrap.zig passes sudo <apt> install -y pkg1 pkg2 ... with the full package list, and the brew bundle path in apply.zig does the same. A dozen packages easily exceeds 256 bytes.

Impact: assertion panic in Debug/ReleaseSafe; heap corruption in ReleaseFast.

Fix

  • Use the allocating append/appendSlice variants so the buffer grows as needed.
  • Extract the string building into a joinArgs helper and cover it with tests, including an argv well past the initial capacity.
  • Add command_runner.zig to the test-discovery comptime block in main.zig (its tests were not being collected before).

Testing

  • zig build test — 11 tests pass (2 new).

…apacity

The display/logging command string was built with appendAssumeCapacity
on a 256-byte buffer (capacity 0 if the initial allocation failed).
Any argv longer than 256 bytes -- e.g. a routine 'apt-get install'
or 'brew bundle' invocation with a dozen packages -- overflowed the
buffer: an assertion panic in Debug/ReleaseSafe and heap corruption
in ReleaseFast.

Use the allocating append/appendSlice variants so the buffer grows as
needed, extract the string building into joinArgs, and cover it with
tests including an argv well past the initial capacity.
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