Skip to content

[5.9] Clamp the length for WriteFile calls on win32 pipes. #802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -2510,6 +2510,23 @@ _dispatch_operation_perform(dispatch_operation_t op)
}
bSuccess = TRUE;
} else if (GetFileType(hFile) == FILE_TYPE_PIPE) {
// WriteFile with more bytes than are available in the
// buffer of a NOWAIT pipe will immediately return 0,
// so clamp our requested write length to make progress.
IO_STATUS_BLOCK iosb;
FILE_PIPE_LOCAL_INFORMATION fpli;
NTSTATUS status = _dispatch_NtQueryInformationFile(hFile,
&iosb, &fpli, sizeof(fpli), FilePipeLocalInformation);
if (NT_SUCCESS(status)) {
// WriteQuotaAvailable is unreliable in the presence
// of a blocking reader, when it can return zero, so only
// account for it otherwise
if (fpli.WriteQuotaAvailable > 0) {
len = MIN(len, fpli.WriteQuotaAvailable);
}
len = MIN(len, fpli.OutboundQuota);
}

OVERLAPPED ovlOverlapped = {};
bSuccess = WriteFile(hFile, buf, (DWORD)len,
(LPDWORD)&processed, &ovlOverlapped);
Expand Down