Skip to content

asyncio: Possible missing typecheck in overlapped.c #98793

Closed

Description

@JelleZijlstra

I don't have a Windows machine to check, but I noticed while reading code that the _overlapped.WSAConnect() function calls PyTuple_GET_SIZE on its argument without checking that it is actually a tuple (

switch (PyTuple_GET_SIZE(obj)) {
).

The following code should reproduce the problem and access out-of-bounds memory:

import asyncio.windows_events
import socket
ip = asyncio.windows_events.IocpProactor()
sock = socket.socket(type=socket.SOCK_DGRAM)
ip.connect(sock, None)

Activity

  1. serhiy-storchaka commented on Oct 28, 2022

    @serhiy-storchaka
    Member

    It is checked in _overlapped.Overlapped.ConnectEx, but not in _overlapped.WSAConnect and _overlapped.Overlapped.WSASendTo.

  2. Fidget-Spinner commented on Oct 28, 2022

    @Fidget-Spinner
    Member

    I can confirm on Windows debug build that this gives me:
    Assertion failed: PyTuple_Check(op), file D:\Ken\Documents\GitHub\cpython\Include\cpython\tupleobject.h, line 23
    So there needs to be a type check somewhere.

  3. serhiy-storchaka commented on Oct 28, 2022

    @serhiy-storchaka
    Member

    I have marked it as "easy" because the fix is trivial -- just use corresponding Argument Clinic declaration in other methods as in _overlapped.Overlapped.ConnectEx. The nontrivial part is writing tests for both of affected functions. It needs an access to Windows and some time, so I left it to other contributors.

  4. LUCIOUS999 commented on Oct 28, 2022

    @LUCIOUS999
  5. CharlieZhao95 commented on Oct 29, 2022

    @CharlieZhao95
    Contributor

    I'm trying to create a PR for this issue and it won't take long :)

  6. added a commit that references this issue on Oct 30, 2022
  7. added 2 commits that reference this issue on Oct 31, 2022
  8. added 2 commits that reference this issue on Oct 31, 2022
  9. hauntsaninja commented on Nov 6, 2022

    @hauntsaninja
    Contributor

    Thanks, looks like this has been completed!

  10. Repository owner moved this from Todo to Done in asyncioon Nov 6, 2022
  11. added 2 commits that reference this issue on Oct 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions