classification
Title: SSL recv_into requires the object to implement __len__ unlike socket one
Type: behavior Stage: patch review
Components: SSL Versions: Python 3.9, Python 3.8, Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: christian.heimes Nosy List: ZackerySpytz, christian.heimes, serhiy.storchaka, tzickel
Priority: normal Keywords: patch

Created on 2020-04-12 17:28 by tzickel, last changed 2020-05-22 05:35 by ZackerySpytz.

Pull Requests
URL Status Linked Edit
PR 20310 open ZackerySpytz, 2020-05-22 05:35
Messages (2)
msg366257 - (view) Author: (tzickel) * Date: 2020-04-12 17:28
I am writing this as a bug, as I have an object which implements the buffer protocol but not the __len__.

SSL's recv_into seems to require the buffer object to implement __len__, but this is unlike the socket recv_into which uses the buffer protocol length.

Here is the socket.recv_into implementation:
https://github.com/python/cpython/blob/402e1cdb132f384e4dcde7a3d7ec7ea1fc7ab527/Modules/socketmodule.c#L3556

as you can see, the length is optional, and it not given, it takes it from the buffer protocol length.

But here is SSL recv_into implementation:
https://github.com/python/cpython/blob/master/Lib/ssl.py#L1233

if length is not given, it tries to call the __len__ of the object itself (not it's buffer protocol).
msg367742 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-04-30 06:48
Yes, it is a bug. __len__ can return a value different from the amount of bytes (in array.array, memoryview).

len(buffer) can be replaced with memoryview(buffer).nbytes, but maybe we could keep None and let the lower level to handle it.
History
Date User Action Args
2020-05-22 05:35:19ZackerySpytzsetkeywords: + patch
nosy: + ZackerySpytz

pull_requests: + pull_request19579
stage: patch review
2020-04-30 06:48:40serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg367742
2020-04-30 00:02:37terry.reedysetversions: - Python 3.6
2020-04-12 17:28:18tzickelcreate