Skip to content
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

SSL recv_into requires the object to implement __len__ unlike socket one #84443

Closed
tzickel mannequin opened this issue Apr 12, 2020 · 2 comments
Closed

SSL recv_into requires the object to implement __len__ unlike socket one #84443

tzickel mannequin opened this issue Apr 12, 2020 · 2 comments
Assignees
Labels
3.11 only security fixes 3.12 bugs and security fixes 3.13 new features, bugs and security fixes topic-SSL type-bug An unexpected behavior, bug, or error

Comments

@tzickel
Copy link
Mannequin

tzickel mannequin commented Apr 12, 2020

BPO 40262
Nosy @tiran, @serhiy-storchaka, @tzickel, @ZackerySpytz
PRs
  • gh-84443: SSLSocket.recv_into() shouldn't require __len__ #20310
  • 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:

    assignee = 'https://github.com/tiran'
    closed_at = None
    created_at = <Date 2020-04-12.17:28:17.837>
    labels = ['expert-SSL', '3.8', 'type-bug', '3.7', '3.9']
    title = 'SSL recv_into requires the object to implement __len__ unlike socket one'
    updated_at = <Date 2020-05-22.05:35:19.503>
    user = 'https://github.com/tzickel'

    bugs.python.org fields:

    activity = <Date 2020-05-22.05:35:19.503>
    actor = 'ZackerySpytz'
    assignee = 'christian.heimes'
    closed = False
    closed_date = None
    closer = None
    components = ['SSL']
    creation = <Date 2020-04-12.17:28:17.837>
    creator = 'tzickel'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 40262
    keywords = ['patch']
    message_count = 2.0
    messages = ['366257', '367742']
    nosy_count = 4.0
    nosy_names = ['christian.heimes', 'serhiy.storchaka', 'tzickel', 'ZackerySpytz']
    pr_nums = ['20310']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue40262'
    versions = ['Python 3.7', 'Python 3.8', 'Python 3.9']

    Linked PRs

    @tzickel
    Copy link
    Mannequin Author

    tzickel mannequin commented Apr 12, 2020

    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:

    /* If nbytes was not specified, use the buffer's length */

    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).

    @tzickel tzickel mannequin added 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes labels Apr 12, 2020
    @tzickel tzickel mannequin assigned tiran Apr 12, 2020
    @tzickel tzickel mannequin added topic-SSL type-bug An unexpected behavior, bug, or error 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes labels Apr 12, 2020
    @tzickel tzickel mannequin assigned tiran Apr 12, 2020
    @tzickel tzickel mannequin added topic-SSL type-bug An unexpected behavior, bug, or error labels Apr 12, 2020
    @serhiy-storchaka
    Copy link
    Member

    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.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @serhiy-storchaka serhiy-storchaka added 3.11 only security fixes 3.12 bugs and security fixes 3.13 new features, bugs and security fixes and removed 3.9 only security fixes 3.8 only security fixes 3.7 (EOL) end of life labels Nov 27, 2023
    serhiy-storchaka added a commit that referenced this issue Nov 27, 2023
    …size != 1 (GH-20310)
    
    It is also no longer use __len__().
    
    Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
    miss-islington pushed a commit to miss-islington/cpython that referenced this issue Nov 27, 2023
    …h itemsize != 1 (pythonGH-20310)
    
    It is also no longer use __len__().
    
    (cherry picked from commit 812360f)
    
    Co-authored-by: Zackery Spytz <zspytz@gmail.com>
    Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
    serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Nov 27, 2023
    …col with itemsize != 1 (pythonGH-20310)
    
    It is also no longer use __len__().
    
    (cherry picked from commit 812360f)
    
    Co-authored-by: Zackery Spytz <zspytz@gmail.com>
    Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
    serhiy-storchaka added a commit that referenced this issue Nov 27, 2023
    …th itemsize != 1 (GH-20310) (GH-112458)
    
    It is also no longer use __len__().
    
    (cherry picked from commit 812360f)
    
    Co-authored-by: Zackery Spytz <zspytz@gmail.com>
    Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
    serhiy-storchaka added a commit that referenced this issue Nov 27, 2023
    …th itemsize != 1 (GH-20310) (GH-112459)
    
    It is also no longer use __len__().
    
    (cherry picked from commit 812360f)
    
    Co-authored-by: Zackery Spytz <zspytz@gmail.com>
    aisk pushed a commit to aisk/cpython that referenced this issue Feb 11, 2024
    …h itemsize != 1 (pythonGH-20310)
    
    It is also no longer use __len__().
    
    Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes 3.12 bugs and security fixes 3.13 new features, bugs and security fixes topic-SSL type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants