Skip to content

fix(builtins): cap AWK printf width/precision to prevent memory exhaustion#1048

Merged
chaliy merged 3 commits intomainfrom
fix/issue-983-awk-printf-width
Apr 4, 2026
Merged

fix(builtins): cap AWK printf width/precision to prevent memory exhaustion#1048
chaliy merged 3 commits intomainfrom
fix/issue-983-awk-printf-width

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented Apr 3, 2026

Summary

  • Cap width and precision values to 10,000 in AWK format_string()
  • Return error + exit code 2 when limit exceeded
  • Apply same cap to bash printf builtin width parsing for consistency
  • Prevents ~1GB allocation from printf "%999999999d", 1

Test plan

  • awk '{printf "%999999999d", 1}' rejected with error, exit 2
  • awk '{printf "%999999999.5f", 1}' rejected with error, exit 2
  • awk '{printf "%20d\n", 42}' works correctly
  • awk '{printf "%10000d\n", 1}' works at boundary
  • All 1929 existing spec tests pass

Closes #983

chaliy added 2 commits April 4, 2026 01:18
… mismatch

Bashkit intentionally caps printf width/precision to prevent OOM,
which differs from real bash. Mark those tests with bash_diff directive
so they're excluded from bash_comparison_tests.
@chaliy chaliy force-pushed the fix/issue-983-awk-printf-width branch from aa04e9f to 83d689c Compare April 4, 2026 01:30
@chaliy chaliy merged commit b65dce2 into main Apr 4, 2026
27 checks passed
@chaliy chaliy deleted the fix/issue-983-awk-printf-width branch April 4, 2026 01:40
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.

AWK printf width specifier allows unbounded memory allocation

1 participant