Skip to content

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

Closed

Description

@tzickel
mannequin
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

    Activity

    1. tzickel commented on Apr 12, 2020

      tzickelmannequin
      MannequinAuthor

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

    2. serhiy-storchaka commented on Apr 30, 2020

      @serhiy-storchaka
      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.

    3. transferred this issue fromon Apr 10, 2022
    4. added
      3.11only security fixes
      3.12only security fixes
      3.13only security fixes
      and removed on Nov 27, 2023
    5. added a commit that references this issue on Nov 27, 2023
    6. added a commit that references this issue on Nov 27, 2023
    7. added 3 commits that reference this issue on Nov 27, 2023
    8. added a commit that references this issue on Feb 11, 2024
    9. added a commit that references this issue on Sep 2, 2024
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    3.11only security fixes3.12only security fixes3.13only security fixestopic-SSLtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions