Configuration Information [Automatically generated, do not change]:
Machine: aarch64
OS: darwin25.4.0
Compiler: clang
Compilation CFLAGS: -DSSH_SOURCE_BASHRC
-DDEFAULT_LOADABLE_BUILTINS_PATH='/opt/homebrew/lib/bash:/usr/local/lib/bash:/usr/lib/bash:/opt/local/lib/bash:/usr/pkg/lib/bash:/opt/pkg/lib/bash:.'
uname output: Darwin Mac 25.5.0 Darwin Kernel Version 25.5.0: Mon Apr 27
20:41:15 PDT 2026; root:xnu-12377.121.6~2/RELEASE_ARM64_T6041 arm64
Machine Type: aarch64-apple-darwin25.4.0

Bash Version: 5.3
Patch Level: 15
Release Status: release (installed via Homebrew; per the mechanism below, a
from-source build should also reproduce)

Description:
On macOS, a here-document whose body exceeds PIPE_BUF (512 bytes on Darwin)
makes bash 5.3 hang forever. bash 5.3 delivers here-documents through a
pipe and writes the entire body into that pipe before the reading process
is forked; once the body exceeds the pipe's 512-byte buffer with no reader
draining it, the write blocks and the shell deadlocks. Apple's /bin/bash
3.2 (temp-file here-docs) and bash on Linux (64 KB pipe buffers) are
unaffected.

Repeat-By (self-contained, no external tools; run under bash 5.3 on macOS):

      printf -v body '%*s' 600 ''    # 600-byte body
      body=${body// /x}
      cat <<EOF
      $body
      EOF
      echo done # never printed on bash 5.3 / macOS

Observed:
- 500-byte body: prints and exits 0 on every bash.
- 600-byte body: /bin/bash 3.2.57 prints + exits 0; /opt/homebrew/bin/bash
5.3.15 hangs indefinitely (must be killed).
- Threshold coincides exactly with `getconf PIPE_BUF /` = 512.
- Independent of variable expansion: a quoted-delimiter here-doc (<<'EOF')
with a literal >512-byte body hangs identically.
- Independent of pipelines / command substitution: a bare top-level `cat
<<EOF` is enough.

Expected:
The here-document should be delivered regardless of size (as via temp files
in bash <= 5.2 and on Linux) and the command should complete.

Why macOS-specific:
Darwin's PIPE_BUF is 512 bytes, so a pipe write larger than that blocks
when no reader has started. Linux pipes buffer 64 KB, so the same code path
only manifests for here-docs larger than 64 KB, masking the bug. This is
NOT Homebrew-specific — any bash 5.3 on macOS should reproduce it; Homebrew
is just the usual way 5.3 lands on a Mac.

Notes:
Appears to be a regression from the move of here-documents to pipes (bash
<= 5.2 and /bin/bash 3.2 are fine). Widely hit via tools that resolve
#!/usr/bin/env bash to Homebrew 5.3 and feed large heredocs (cat <<EOF,
python3 - <<'PY'). Downstream reports (Github): obra/superpowers#571,
CharlesWiltgen/Axiom#24, mvdan/sh#923. No existing bug-bash report found.

Reply via email to