Repository navigation
fix: readers bridge the winux fifo marker (Fixes #1493) - #1502
Merged
Merged
Conversation
…e (Refs #1493) Root cause: since #1038 the shared open layer bridges an on-disk `!<fifo>` marker file to a \\.\pipe\winuxcmd-fifo-<hash> endpoint with POSIX blocking open() semantics. The write side (file_io.cppm create_binary_file) and the shared readers (open_binary_file / read_all_file) all consult is_winux_fifo_w, but a family of reader applets opened operands with a raw std::ifstream over normalize_api_operand(), bypassing the bridge: od -c p read the 7 marker bytes as content instead of blocking on the rendezvous (#1493), same for paste/wc/comm/diff as rubash procsub consumers (rubash#2473; wc and diff were already bridged on main). Reader opens now go through file_io::open_binary_file (the same predicate and rendezvous mechanism the write side uses): - od.cpp read_file_bytes; hexdump.cpp data operand - paste.cpp / comm.cpp / nl.cpp operand reads - md5sum / sha1sum / sha256sum / sha512sum file hashing - cksum.cpp read_crc_file (main CRC operand path) + --check list file Two sibling read-path bugs surfaced by the same probe: - file_io.cppm read_handle_to_string: a bridged fifo handle ends with ReadFile failing ERROR_BROKEN_PIPE / ERROR_NO_DATA / ERROR_HANDLE_EOF once the writer closes; that is clean EOF (GNU read(2) returns 0), not an error -- the accumulated bytes were discarded (uniq p failed with "error reading 'p'"). Mirrors the rule read_all_stdin already applies to fd 0. - wc.cpp: GNU takes the st_size shortcut only for regular files (wc.c S_ISREG); a fifo marker IS a regular file on NTFS, so `wc -c p` reported the 7 marker bytes and the width-total loop counted markers as regular sizes. Markers now fall through to the streaming count / non-regular width floor. GNU oracle (WSL bash, script-file harness, byte-for-byte): mkfifo + background writer x od -c / od -An -tx1 / hexdump -c / wc [-c] / cat / nl / paste (two fifos) / comm (two fifos) / uniq / md5sum / sha1sum / sha256sum / sha512sum / cksum / 128 KiB payload -- all byte-identical. 11 new mkfifo rendezvous unit tests pin these (incl. the rubash#2473 paste-of-two-fifos shape and GNU blocking-without-writer semantics, cancellable by Ctrl-C / external termination). Out of scope, listed for follow-up (NOT silently changed): grep/sed engine opens (their BOM/binary fast paths consume stream bytes and need their own pipe audit), less/more pagers, and the remaining config-file readers (column/rev/strings/expand/unexpand/fold/fmt/csplit/split/d2u/ du excludes/dircolors/hostname/ldd). Refs #1493, Refs rubash#2473
caomengxuan666
marked this pull request as ready for review
November 2, 2026 01:31
This was referenced Nov 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WIP: fix(fifo): reader-applet operand opens bridge the
!<fifo>marker (Refs #1493, Refs rubash#2473; targeting 1.2.1)Root cause
Since #1038 the shared open layer (
src/utils/file_io.cppm) bridges anon-disk
!<fifo>marker file (src/utils/native_path.cppm:1082 kFifoMarker,is_winux_fifo_w) to a deterministic\\.\pipe\winuxcmd-fifo-<hash>endpoint with POSIX blockingopen()semantics:
file_io.cppm:134 open_fifo_read_handle—CreateNamedPipeWConnectNamedPipe, blocks until a writer arrives;file_io.cppm:149 open_fifo_write_handle—CreateFileWretry loop, blocks until a reader creates the endpoint.
The write side and the shared readers
(
open_binary_file/create_binary_file/read_all_file) all consultis_winux_fifo_w— but a family of reader applets opened operands witha raw
std::ifstreamovernormalize_api_operand(), bypassing thebridge entirely and reading the 7 marker bytes as file content. That is
the asymmetry #1493 reports:
od -c pprinted!<fifo>literallywhile
echo hi > pcorrectly blocked in the write-bridge rendezvous.The asymmetry points fixed (all now via
file_io::open_binary_file)src/commands/od.cppread_file_bytes(was :582 raw ifstream)src/commands/hexdump.cppsrc/commands/paste.cppsrc/commands/comm.cppsrc/commands/nl.cppsrc/commands/md5sum.cpp/sha1sum.cpp/sha256sum.cpp/sha512sum.cppsrc/commands/cksum.cppread_crc_file(the main CRC operand path, was :435) +--checklist fileTwo sibling read-path bugs the same probe surfaced
src/utils/file_io.cppm read_handle_to_string: a bridged fifohandle ends with
ReadFilefailingERROR_BROKEN_PIPE/ERROR_NO_DATA/ERROR_HANDLE_EOFonce the writer closes — that isclean EOF (GNU
read(2)returns 0), not an error. The accumulatedbytes were being discarded (
uniq p→error reading 'p'). Thefix mirrors the rule
read_all_stdinalready documents for fd 0.src/commands/wc.cpp: GNU takes thest_sizeshortcut only forregular files (
wc.cS_ISREG); a fifo marker IS a regular file onNTFS, so
wc -c preported the 7 marker bytes (7 pinstead of3 p), and the column-width total loop counted markers as regularsizes. Markers now fall through to the streaming count / the
non-regular width floor.
GNU oracle (WSL GNU bash, script-file harness, byte-for-byte)
mkfifo+ background writer ×od -c/od -An -tx1/hexdump -c/wc [-c]/cat/nl/paste(two fifos) /comm(two fifos) /uniq/md5sum/sha1sum/sha256sum/sha512sum/cksum/128 KiB payload — 16/16 outputs byte-identical to WSL GNU
(including the rubash#2473 reproducer shape
paste <(echo 1) <(echo x)→
1\tx).Artifacts:
/d/tmp/wc1493/oracle.sh/oracle-full.out(GNU side) vsprobe2.sh/probe2.out(WinuxCmd side), run in this session.Boundary behavior (GNU semantics kept)
open(O_RDONLY)blocks inGNU) and is cancellable via Ctrl-C or external termination — pinned
by
mkfifo.reader_without_writer_blocks_like_gnu.test -p/stat -c %F(fifo) /find -type p/ls -l(ptype bit) keep identifying markers as FIFOs (pre-existing, verified
not regressed).
ls -l's size column still shows the marker's 7where GNU shows 0 — pre-existing cosmetic difference, left as is.
read_handle_to_string's newbroken-pipe cases cannot occur on regular files, and
wc's markercheck is attributes-gated (
FILE_ATTRIBUTE_SYSTEM+ first-7-byteprobe) inside
is_winux_fifo_w.Tests
11 new unit tests in
tests/unit/mkfifo/mkfifo_unit_test.cpp(od, wc-c, wc full, md5sum, cksum, paste×2-fifos, comm×2-fifos, nl, hexdump,
uniq broken-pipe-EOF, blocking-without-writer), each pinning GNU
byte-exact output with a background
teewriter and a 10 srendezvous-deadline guard so a regression fails instead of hanging the
suite.
od.*:wc.*:cksum.*:md5sum.*:sha*sum.*:comm.*:paste.*:nl.*:hexdump.*:uniq.*:mkfifo.*:cat.*:tee.*:sort.*:head.*:tail.*):528/529 pass; the 1 failure (
cat.nul_txt_reads_file_issue1333)is proven pre-existing on clean main (stash-verified) and is part of
the known environment-bound
NUL.txtdevice-name family.ctest: 3648/3667 pass; the 19 failures are, by name, thesame environment-bound set that fails on clean main in this sandbox
(
nul_txt×4,shell_root/issue1364/issue1385×13, nohup ×2) —and main additionally fails
md5sum/cksum.issue_1288_ignore_missing…there, which pass with this PR.
Deliberately out of scope (follow-ups, not silently changed)
grep/sedengine operand opens: their BOM/binary fast paths(
should_stream_file_fast_path) consume stream bytes and need theirown pipe audit before bridging.
less/morepagers,column/rev/strings/expand/unexpand/fold/fmt/csplit/split/d2uand config-file readers(
duexcludes,dircolors,hostname -F,ldd): same raw-ifstreamshape, lower FIFO likelihood; left for a follow-up sweep.
Docs
DOCS/gnu-coreutils/mkfifo.mdstill described FIFOs as unsupported;rewritten to describe the #1038 marker + bridge design and the #1493
reader-side unification.
Refs #1493, Refs unixwin/rubash#2473