Skip to content

Commit b963149

Browse files
alexbrainmanodeke-em
authored andcommitted
net: do not call Windows TransmitFile for large files
TransmitFile does not allow for number of bytes that can be transmitted to be larger than 2147483646. See https://docs.microsoft.com/en-us/windows/win32/api/mswsock/nf-mswsock-transmitfile for details. So adjust sendFile accordingly. No test added, because this would require creating large file (more than 2GB file). Fixes #33193. Change-Id: I82e0cb104d112264e4ea363bb20b6d02ac30b38e Reviewed-on: https://go-review.googlesource.com/c/go/+/187037 Run-TryBot: Alex Brainman <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Emmanuel Odeke <[email protected]>
1 parent 997086b commit b963149

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/net/sendfile_windows.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ func sendFile(fd *netFD, r io.Reader) (written int64, err error, handled bool) {
2929
if n <= 0 {
3030
return 0, nil, true
3131
}
32+
// TransmitFile can be invoked in one call with at most
33+
// 2,147,483,646 bytes: the maximum value for a 32-bit integer minus 1.
34+
// See https://docs.microsoft.com/en-us/windows/win32/api/mswsock/nf-mswsock-transmitfile
35+
const maxSendBytes = 0x7fffffff - 1
36+
if n > maxSendBytes {
37+
return 0, nil, false
38+
}
3239
}
3340
f, ok := r.(*os.File)
3441
if !ok {

0 commit comments

Comments
 (0)