Bug report
Bug description:
This came up in python/typeshed#12414.
The current implementation of file_digest() does not check the return value of fileobj.readinto() for None:
|
while True: |
|
size = fileobj.readinto(buf) |
|
if size == 0: |
|
break # EOF |
|
digestobj.update(view[:size]) |
While buffered file objects can't return None, unbuffered ones can when they are doing non-blocking I/O. Specifically, file_digest() is documented to take SocketIO objects, which can very much return None:
|
def readinto(self, b): |
|
"""Read up to len(b) bytes into the writable buffer *b* and return |
|
the number of bytes read. If the socket is non-blocking and no bytes |
|
are available, None is returned. |
|
|
|
If *b* is non-empty, a 0 return value indicates that the connection |
|
was shutdown at the other end. |
|
""" |
|
self._checkClosed() |
|
self._checkReadable() |
|
if self._timeout_occurred: |
|
raise OSError("cannot read from timed out object") |
|
try: |
|
return self._sock.recv_into(b) |
|
except timeout: |
|
self._timeout_occurred = True |
|
raise |
|
except error as e: |
|
if e.errno in _blocking_errnos: |
|
return None |
|
raise |
CPython versions tested on:
CPython main branch
Operating systems tested on:
Other
Linked PRs
Bug report
Bug description:
This came up in python/typeshed#12414.
The current implementation of
file_digest()does not check the return value offileobj.readinto()forNone:cpython/Lib/hashlib.py
Lines 232 to 236 in 2a5d1eb
While buffered file objects can't return
None, unbuffered ones can when they are doing non-blocking I/O. Specifically,file_digest()is documented to takeSocketIOobjects, which can very much returnNone:cpython/Lib/socket.py
Lines 694 to 714 in 2a5d1eb
CPython versions tested on:
CPython main branch
Operating systems tested on:
Other
Linked PRs