Skip to content

Commit 5c97a05

Browse files
committed
Cygwin: pipe: Fix hang due to inadvertent 0-length raw_write()
It is possible for `NtQueryInformationFile()` to report a 0-length `InboundQuota` when obtaining `FilePipeLocalInformation`. This seems to be the case e.g. when a pipe was created on the other side and its quota information is not available on the client side. This can lead to a situation where the `avail` variable is set to 0, and since that is used to cap the number of bytes to send, a 0-length write. Which hangs forever. This was observed in the MSYS2 project when building GIMP, and reduced to a simple test case where a MINGW `ninja.exe` tries to call an MSYS `bison.exe` and the error message (saying that `bison` wants to have some input) is not even shown. Since the minimal pipe buffer size is 4k, let's ensure that it is at least that, even when `InboundQuota` reports 0. This fixes msys2/msys2-runtime#270 Fixes: cbfaeba (Cygwin: pipe: Fix incorrect write length in raw_write()) Helped-by: Corinna Vinschen <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent bcbfa28 commit 5c97a05

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

winsup/cygwin/fhandler/pipe.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ fhandler_pipe::set_pipe_buf_size ()
11581158
status = NtQueryInformationFile (get_handle (), &io, &fpli, sizeof fpli,
11591159
FilePipeLocalInformation);
11601160
if (NT_SUCCESS (status))
1161-
pipe_buf_size = fpli.InboundQuota;
1161+
pipe_buf_size = fpli.InboundQuota < PIPE_BUF ? PIPE_BUF : fpli.InboundQuota;
11621162
}
11631163

11641164
int

0 commit comments

Comments
 (0)