Skip to content

fix: printf %b support and no-progress guard against format-recycle hangs#50

Merged
ivarvong merged 1 commit into
mainfrom
fix/printf-b-hang
Jul 3, 2026
Merged

fix: printf %b support and no-progress guard against format-recycle hangs#50
ivarvong merged 1 commit into
mainfrom
fix/printf-b-hang

Conversation

@ivarvong

@ivarvong ivarvong commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Found while running agents against the sandbox: printf "%b" "A\xffB\n" — an ordinary command any agent will eventually type — hung JustBash.exec/2 forever. An untrusted script could take down the host with one line.

printf recycles its format string while arguments remain, but %b was not in the format regex, so each recycle pass consumed zero arguments and recursed with the same list. The same hang fired for any unrecognized directive with at least one argument (%q, %v, %i, …).

Two changes:

  • %b is now a real directive, sharing echo -e's escape dialect (\n, \t, \xHH, \0NNN — exposed as Echo.interpret_escapes/1), so printf "%b" "A\xffB\n" emits the raw bytes bash does.
  • A recycle pass that consumes no arguments stops after one iteration — the hang class is closed for every unknown directive, present and future. Unknown directives pass through literally where bash reports invalid format character; the divergence is noted in the tests.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FpxHS5iGm9ktgpnL9QZu9x

…angs

printf recycles its format while arguments remain, but a directive the
format regex doesn't recognize consumes nothing — so printf "%b" "x"
(or any unknown directive with an argument) looped forever, hanging the
host process. %b is now a real directive sharing echo -e's escape
dialect, and a recycle pass that consumes no arguments stops after one
iteration instead of recursing. Unknown directives pass through
literally where bash errors; the divergence is noted in the tests.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FpxHS5iGm9ktgpnL9QZu9x
@ivarvong
ivarvong merged commit 56c74b8 into main Jul 3, 2026
3 checks passed
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