Skip to content

limits: fd table caps at 1014 with "cannot duplicate fd: Invalid argument"; read counts NUL bytes where cmdsub drops them silently; closed fd 0 then redirect errors #773

Closed

Description

@caomengxuan666

Summary

Three robustness/limits items, all low severity but all "the shell reports something that isn't true". Measured on master b5793580 (built 2026-10-17 14:25), oracle WSL GNU bash 5.3.0.

1. fd table caps at 1014, with a misleading errno

i=0; while [ $i -lt 1200 ]; do exec {fd}>>f || break; i=$((i+1)); done; echo "allocated=$i"
result stderr
GNU bash 5.3.0 allocated=1200 (the loop bound; GNU's own limit is higher) —
master b5793580 allocated=1014 (fd ≤ 1023) redirection error: cannot duplicate fd: Invalid argument

The cap is defensible (a Windows handle budget); the diagnostic is not: GNU says Too many open files for this condition, and Invalid argument points the reader at the wrong thing entirely. A script that retries on EMFILE will not recognise this message, and a human will debug the wrong layer.

2. NUL bytes: read counts them, command substitution is silent about them

printf 'abc\0def\0\n' > f
x=$(cat f);        echo "cmdsub_len=${#x}"
IFS= read -r z < f; echo "read_len=${#z}"
cmdsub_len read_len stderr
GNU bash 5.3.0 6 6 warning: command substitution: ignored null byte in input
master b5793580 6 8 (silent)

So the two paths disagree with each other as well as with GNU: the substitution drops the NULs (like GNU, but without the warning that makes it discoverable), while read keeps them and counts them. Note the silence is the part that matters most in this codebase's own taxonomy — it is the same "wrong value, no diagnostic" profile as the other silent items.

3. Closed fd 0, then a redirect: spurious Bad file descriptor

exec 0<&-
read y < /dev/null
echo "rc=$? y=[$y]"
stdout stderr
GNU bash 5.3.0 rc=1 y=[] (nothing)
master b5793580 rc=1 y=[] — same read: 0: read error: Bad file descriptor

Exit status and value already match GNU; the only divergence is the diagnostic. Worth folding into whatever "fd 0 is a special case" work is planned (#721 is adjacent), or closing as wording.

Method

Same harness as the catalogue: LF scripts, WSL GNU bash 5.3.0 oracle, arm bounded, fixtures per arm, stdout/stderr/rc separate. All three pinned as catalogue cases in #746.

Activity

  1. added
    bug
    P3-low
    area:fd
    area:read
    on Oct 17, 2026
  2. added a commit that references this issue on Oct 19, 2026
  3. added a commit that references this issue on Oct 20, 2026
  4. caomengxuan666 commented on Oct 22, 2026

    @caomengxuan666
    MemberAuthor

    Item 2 (bare read keeps embedded NULs) still reproduces on niubash 1.4.4 / rubash master ~2026-10:

    printf "a\0b\n" | { read x; echo "len=${#x}"; }
    # GNU bash 5.3:  len=2
    # rubash:        len=3

    Same for read -r and multi-var reads. Note read -d "" and mapfile -d "" with NUL-delimited input MATCH GNU — only bare read diverges. Reopening candidate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3-lowarea:fdarea:readbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions