bpo-17560: Too small type for struct.pack/unpack in mutliprocessing.Connection (GH-10305)

Allow sending more than 2 GB at once on a multiprocessing connection on non-Windows systems.
This commit is contained in:
Alexander Buchkovsky 2018-11-06 21:38:34 +02:00 committed by Antoine Pitrou
parent 75d9d59ab3
commit bccacd19fa
2 changed files with 21 additions and 10 deletions

View file

@ -389,7 +389,14 @@ class Connection(_ConnectionBase):
def _send_bytes(self, buf): def _send_bytes(self, buf):
n = len(buf) n = len(buf)
# For wire compatibility with 3.2 and lower if n > 0x7fffffff:
pre_header = struct.pack("!i", -1)
header = struct.pack("!Q", n)
self._send(pre_header)
self._send(header)
self._send(buf)
else:
# For wire compatibility with 3.7 and lower
header = struct.pack("!i", n) header = struct.pack("!i", n)
if n > 16384: if n > 16384:
# The payload is large so Nagle's algorithm won't be triggered # The payload is large so Nagle's algorithm won't be triggered
@ -406,6 +413,9 @@ class Connection(_ConnectionBase):
def _recv_bytes(self, maxsize=None): def _recv_bytes(self, maxsize=None):
buf = self._recv(4) buf = self._recv(4)
size, = struct.unpack("!i", buf.getvalue()) size, = struct.unpack("!i", buf.getvalue())
if size == -1:
buf = self._recv(8)
size, = struct.unpack("!Q", buf.getvalue())
if maxsize is not None and size > maxsize: if maxsize is not None and size > maxsize:
return None return None
return self._recv(size) return self._recv(size)

View file

@ -0,0 +1 @@
Allow sending more than 2 GB at once on a multiprocessing connection on non-Windows systems.