Merge pull request #1859 from lbryio/fix_invalid_data_client

handle and log if downloading from bad sendfile implementations
This commit is contained in:
Jack Robison 2019-02-04 17:19:57 -05:00 committed by GitHub
commit b9934a7eb7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -51,9 +51,14 @@ class BlobExchangeClientProtocol(asyncio.Protocol):
if response.blob_data and self.writer and not self.writer.closed(): if response.blob_data and self.writer and not self.writer.closed():
log.debug("got %i blob bytes from %s:%i", len(response.blob_data), self.peer_address, self.peer_port) log.debug("got %i blob bytes from %s:%i", len(response.blob_data), self.peer_address, self.peer_port)
# write blob bytes if we're writing a blob and have blob bytes to write # write blob bytes if we're writing a blob and have blob bytes to write
self._blob_bytes_received += len(response.blob_data) if len(response.blob_data) > (self.blob.get_length() - self._blob_bytes_received):
data = response.blob_data[:(self.blob.get_length() - self._blob_bytes_received)]
log.warning("got more than asked from %s:%d, probable sendfile bug", self.peer_address, self.peer_port)
else:
data = response.blob_data
self._blob_bytes_received += len(data)
try: try:
self.writer.write(response.blob_data) self.writer.write(data)
return return
except IOError as err: except IOError as err:
log.error("error downloading blob from %s:%i: %s", self.peer_address, self.peer_port, err) log.error("error downloading blob from %s:%i: %s", self.peer_address, self.peer_port, err)