Use sendall to ensure all bytes sent#35
Closed
nwray-credibly wants to merge 64 commits intograingert:masterfrom
Closed
Use sendall to ensure all bytes sent#35nwray-credibly wants to merge 64 commits intograingert:masterfrom
nwray-credibly wants to merge 64 commits intograingert:masterfrom
Conversation
In his fork, Thomas Grainger wrote: > This is a fork of pyClamd v0.2.0 created by Philippe Lagadec and published on > his website: http://www.decalage.info/en/python/pyclamd which in turn is a > slightly improved version of pyClamd v0.1.1 created by Alexandre Norman and > published on his website: http://xael.org/norman/python/pyclamd/. Philippe's fork was published under the `GPL-2.0` license. I'm not a lawyer but what I read is that Philippe re-licensed it under `GPL-2.0` and it cannot rever to `LGPL`. I'm using `GPL-2.0` to comply with the existing licensing chain.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In clamav_client.clamd there are three uses of self.clamd_socket.sendall. Socket.send is a low-level function which does not (necessarily, by contract) send the entire buffer. Instead it returns the number of bytes actually sent, and the caller is required to manage the unsent bytes by passing them to socket.send until all are sent.
from the python spec for send: https://docs.python.org/3/library/socket.html#socket.socket.send
"_Send data to the socket. The socket must be connected to a remote socket. The optional flags argument has the same meaning as for recv() above. Returns the number of bytes sent. Applications are responsible for checking that all data has been sent; if only some of the data was transmitted, the application needs to attempt delivery of the remaining data. _
compare to sendall: https://docs.python.org/3/library/socket.html#socket.socket.sendall
Unlike send(), this method continues to send data from bytes until either all data has been sent or an error occurs.
In the existing code, the return value from socket.send is not checked. This is something the library generally "gets away with" since it is sending at most 1024 bytes per send. However under gevent this is causing failures since the threads are changed more frequently. So we're seeing the impact of this defect (as was the author of this PR in 2021 against the source repo of clamd: #23).
The PR presented replaces the low-level "send" call with the required "sendall" call which behaves as the code appears to expect.