alekstorm / backports.ssl

UNMAINTAINED - The Python 3.4 standard `ssl` module API implemented on top of pyOpenSSL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

_fileobject.read() is pretty badly broken

jim-minter opened this issue · comments

There are several significant issues here:

  1. Depending on timing, when read() is called and the remote end terminates its SSL connection cleanly, SSLZeroReturnError will be raised to the user and the final bytes of the stream are lost forever.

                data = _safe_ssl_call(False, self._sock, 'recv', maxbufsize)
                if not data:
                    break
    

    In the above snippet, the second line will not execute when SSLZeroReturnError is raised. data is a local variable and its contents are lost.

  2. There are identical code patterns which need fixing in _fileobject.readline() as well (maybe other places too, I'm not sure).

  3. In the case size < 0, read() does not keep the contract of reading until EOF.

        if size < 0:
            # Read until EOF
            self._rbuf = BytesIO()  # reset _rbuf.  we consume it via buf.
            data = _safe_ssl_call(False, self._sock, 'recv', rbufsize)
            buf.write(data)
            return buf.getvalue()
    

    In the above snippet, the comment is mistaken. There would have to be a loop for it to be true. No more than rbufsize additional bytes are read from the channel.

commented

Hi
Is this related?
mjs/imapclient#268