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

getaddrinfo raises OverflowError #74895

Closed
smejkar mannequin opened this issue Jun 20, 2017 · 12 comments
Closed

getaddrinfo raises OverflowError #74895

smejkar mannequin opened this issue Jun 20, 2017 · 12 comments
Assignees
Labels
extension-modules C modules in the Modules dir topic-IO type-bug An unexpected behavior, bug, or error

Comments

@smejkar
Copy link
Mannequin

smejkar mannequin commented Jun 20, 2017

BPO 30710
Nosy @benjaminp, @serhiy-storchaka, @csabella, @smejkar, @remilapeyre
PRs
  • gh-74895: getaddrinfo no longer raises OverflowError #2435
  • Files
  • getaddrinfo_overflow_error.patch
  • 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 = None
    closed_at = None
    created_at = <Date 2017-06-20.13:19:55.914>
    labels = ['extension-modules', 'type-bug', '3.7']
    title = 'getaddrinfo raises OverflowError'
    updated_at = <Date 2020-05-29.09:57:44.659>
    user = 'https://github.com/smejkar'

    bugs.python.org fields:

    activity = <Date 2020-05-29.09:57:44.659>
    actor = 'remi.lapeyre'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Extension Modules']
    creation = <Date 2017-06-20.13:19:55.914>
    creator = 'smejkar'
    dependencies = []
    files = ['46964']
    hgrepos = []
    issue_num = 30710
    keywords = ['patch']
    message_count = 11.0
    messages = ['296421', '296437', '296471', '296473', '296526', '296536', '296540', '296541', '296548', '370283', '370285']
    nosy_count = 5.0
    nosy_names = ['benjamin.peterson', 'serhiy.storchaka', 'cheryl.sabella', 'smejkar', 'remi.lapeyre']
    pr_nums = ['2435']
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue30710'
    versions = ['Python 3.7']

    Linked PRs

    @smejkar
    Copy link
    Mannequin Author

    smejkar mannequin commented Jun 20, 2017

    If the port argument is a number, getaddrinfo attempts to convert it to a C long, that raises OverflowError if the conversion fails.

    Instead, getaddrinfo should convert the port to a string (bytes) directly and rely on the underlying getaddrinfo to return EAI_SERVICE. This is also consistent with the case when a numeric port is passed as a string.

    @smejkar smejkar mannequin added stdlib Python modules in the Lib dir 3.7 (EOL) end of life type-bug An unexpected behavior, bug, or error labels Jun 20, 2017
    @serhiy-storchaka
    Copy link
    Member

    What do you mean by converting the port to a string (bytes) directly? Can you provide an example?

    @smejkar
    Copy link
    Mannequin Author

    smejkar mannequin commented Jun 20, 2017

    Use PyObject_Str and PyUnicode_AsUTF8 if the port argument is a PyLong instead of converting it to an intermediate C long that may raise OverflowError. See getaddrinfo_overflow_error.patch

    @smejkar smejkar mannequin added extension-modules C modules in the Modules dir and removed stdlib Python modules in the Lib dir labels Jun 20, 2017
    @serhiy-storchaka
    Copy link
    Member

    Now I understand your idea. It looks reasonable to me. Could you create a pull request on GitHub? Please provide also tests, add a Misc/NEWS entry and add your name in Misc/ACKS.

    But how large is the performance hit of this change? It adds at least one additional memory allocation for the str object. If the slowdown is significant perhaps it is worth to keep the old code as a fast path.

    @benjaminp
    Copy link
    Contributor

    Why can't the user simply pass in a string service name in the first place?

    @smejkar
    Copy link
    Mannequin Author

    smejkar mannequin commented Jun 21, 2017

    But how large is the performance hit of this change? It adds at least one additional memory allocation for the str object. If the slowdown is significant perhaps it is worth to keep the old code as a fast path.

    commit 5cc7ac2
    ./python -m timeit -s 'import socket' 'socket.getaddrinfo(None, 1000)'
    2000 loops, best of 5: 139 usec per loop
    ./python -m timeit -s 'import socket' 'socket.getaddrinfo(None, "1000")'
    2000 loops, best of 5: 142 usec per loop

    with getaddrinfo_overflow_error.patch
    ./python -m timeit -s 'import socket' 'socket.getaddrinfo(None, 1000)'
    2000 loops, best of 5: 140 usec per loop
    ./python -m timeit -s 'import socket' 'socket.getaddrinfo(None, "1000")'
    2000 loops, best of 5: 139 usec per loop

    It seems the impact on performance is negligible/not measurable.

    @serhiy-storchaka
    Copy link
    Member

    I like your idea about getting rid of OverflowError. But wouldn't it make the problem with other reported by you issue, bpo-30711, worse?

    @smejkar
    Copy link
    Mannequin Author

    smejkar mannequin commented Jun 21, 2017

    Why can't the user simply pass in a string service name in the first place?
    He/she can. But I don't propose to change that. The patch only changes the way a given number is converted to a string. That is, without an intermediate C long.

    @smejkar
    Copy link
    Mannequin Author

    smejkar mannequin commented Jun 21, 2017

    I like your idea about getting rid of OverflowError. But wouldn't it make the problem with other reported by you issue, bpo-30711, worse?

    It depends on the implementation of the underlying getaddrinfo. For Modules/getaddrinfo.c, it will be worse for positive numbers outside the C long range.

    @csabella
    Copy link
    Contributor

    The original pull request has been closed as inactive. If the original author is interested in pursuing this issue, it can be reopened or someone else can create a new pull request to replace it.

    @remilapeyre
    Copy link
    Mannequin

    remilapeyre mannequin commented May 29, 2020

    Hi Cheryl Sabella, the pull request that got closed is the one for bpo-30711. The pull request for this one has never been reviewed.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @arhadthedev arhadthedev added topic-IO and removed 3.7 (EOL) end of life labels Feb 13, 2023
    @gpshead gpshead self-assigned this Feb 13, 2023
    gpshead pushed a commit that referenced this issue Feb 14, 2023
    `socket.getaddrinfo()` no longer raises `OverflowError` based on the **port** argument. Error reporting (or not) for its value is left up to the underlying C library `getaddrinfo()` implementation.
    @gpshead
    Copy link
    Member

    gpshead commented Feb 14, 2023

    thanks! Fixed to just rely on the underlying C library API for an error indicator or not. I'm not backporting this bugfix as it is very minor and changes in exception behavior are API changes that can be surprising, even if we don't think anything should be relying on it.

    @gpshead gpshead closed this as completed Feb 14, 2023
    kulikjak added a commit to kulikjak/cpython that referenced this issue May 9, 2023
    gpshead pushed a commit that referenced this issue May 9, 2023
    Solaris is unusual here, but apparently everyone is happy when SOCK_STREAM is explicitly specified.
    carljm added a commit to carljm/cpython that referenced this issue May 10, 2023
    * main:
      pythonGH-102181: Improve specialization stats for SEND (pythonGH-102182)
      pythongh-103000: Optimise `dataclasses.asdict` for the common case (python#104364)
      pythongh-103538: Remove unused TK_AQUA code (pythonGH-103539)
      pythonGH-87695: Fix OSError from `pathlib.Path.glob()` (pythonGH-104292)
      pythongh-104263: Rely on Py_NAN and introduce Py_INFINITY (pythonGH-104202)
      pythongh-104010: Separate and improve docs for `typing.get_origin` and `typing.get_args` (python#104013)
      pythongh-101819: Adapt _io._BufferedIOBase_Type methods to Argument Clinic (python#104355)
      pythongh-103960: Dark mode: invert image brightness (python#103983)
      pythongh-104252: Immortalize Py_EMPTY_KEYS (pythongh-104253)
      pythongh-101819: Clean up _io windows console io after pythongh-104197 (python#104354)
      pythongh-101819: Harden _io init (python#104352)
      pythongh-103247: clear the module cache in a test in test_importlib/extensions/test_loader.py (pythonGH-104226)
      pythongh-103848: Adds checks to ensure that bracketed hosts found by urlsplit are of IPv6 or IPvFuture format (python#103849)
      pythongh-74895: adjust tests to work on Solaris (python#104326)
      pythongh-101819: Refactor _io in preparation for module isolation (python#104334)
      pythongh-90953: Don't use deprecated AST nodes in clinic.py (python#104322)
      pythongh-102327: Extend docs for "url" and "headers" parameters to HTTPConnection.request()
      pythongh-104328: Fix typo in ``typing.Generic`` multiple inheritance error message (python#104335)
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    extension-modules C modules in the Modules dir topic-IO type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants