New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SSLSocket.recv(-1) triggers SystemError #70831
Comments
SystemError indicates an internal error that is not supposed to be triggerable from Python code. We should probably raise ValueError like plain sockets instead. >>> s = create_connection(("python.org", 443))
>>> s.recv(-1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: negative buffersize in recv
>>> ss = ssl.wrap_socket(s)
>>> ss.recv(-1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/proj/python/cpython/Lib/ssl.py", line 910, in recv
return self.read(buflen)
File "/home/proj/python/cpython/Lib/ssl.py", line 787, in read
return self._sslobj.read(len, buffer)
File "/home/proj/python/cpython/Lib/ssl.py", line 573, in read
v = self._sslobj.read(len or 1024)
SystemError: Negative size passed to PyBytes_FromStringAndSize |
Proposed patch |
Is this what other file-like objects do with negatives sizes? |
Socket objects aren’t exactly file-like. Plain non-SSL sockets don’t even have read() methods. I think giving a meaning to recv(-1) would be an (unwanted) new feature, rather than a bug fix. If you want a file-like object linked to a socket, I would suggest using something like the makefile() method instead of adding to the low-level socket object API. But to answer your question: no, most file methods treat a negative size as a special request to read until EOF, e.g. read(-1), readline(-1) and readlines(-1) of RawIOBase, BufferedIOBase and TextIOBase. On the other hand, BufferedIOBase.read1(-1) is poorly defined and supported (bpo-23214), but may end up meaning something like “read an arbitrary non-zero chunk with a minimum amount of low-level calls and processing”. |
Thanks for the explanation. Your patch lgtm. On Sat, Mar 26, 2016, at 15:01, Martin Panter wrote:
|
Thanks for the reviews. Here is a patch that avoids breaking read(-1, buffer). |
LGTM. |
New changeset af92651c22e9 by Martin Panter in branch '3.5': New changeset b84d136e0028 by Martin Panter in branch '2.7': New changeset 80934ad2356d by Martin Panter in branch 'default': |
The Python 2 fix was slightly different, due to the lack of Argument Clinic. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: