Skip to content

Use sendall to ensure all bytes sent#35

Closed
nwray-credibly wants to merge 64 commits intograingert:masterfrom
RetailCapital:use_sendall_to_ensure_all_bytes_sent
Closed

Use sendall to ensure all bytes sent#35
nwray-credibly wants to merge 64 commits intograingert:masterfrom
RetailCapital:use_sendall_to_ensure_all_bytes_sent

Conversation

@nwray-credibly
Copy link

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.

vstoykov and others added 30 commits September 5, 2024 11:01
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.
@nwray-credibly nwray-credibly deleted the use_sendall_to_ensure_all_bytes_sent branch March 4, 2026 23:45
@nwray-credibly nwray-credibly restored the use_sendall_to_ensure_all_bytes_sent branch March 4, 2026 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants