MagicStack / MagicStack/uvloop

Directly constructed `uvloop.loop.Server(None)` segfaults in `close()`

Open
#760 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Cython
Stars
11.9k
Forks
616
PR merge metrics
No merged PRs in 30d

Description

Summary

uvloop.loop.Server(None) constructs an object, but calling close() on it terminates the interpreter.
I found this while fuzzing Python C extension modules.
I realize this is not a realistic input or usage pattern, but I would expect a Python exception rather than a process crash.

Versions

uvloop 0.22.1, CPython 3.12.3, Debian 12 x86_64, glibc 2.36

Reproducer
from uvloop.loop import Server

server = Server(None)
server.close()
Segmentation fault (core dumped)
ASan/UBSan result

I built uvloop 0.22.1 from source with Clang 18 using ASan and UBSan instrumentation.
ASan reports a read from address 0x158 on the Server.close() path:

AddressSanitizer:DEADLYSIGNAL
ERROR: AddressSanitizer: SEGV on unknown address 0x000000000158
The signal is caused by a READ memory access.
Hint: address points to the zero page.

    #0 PyType_IsSubtype
    #1 CPython set operation
    #2 __Pyx_PySet_Discard  uvloop/loop.c:194862:17
    #3 Server._unref        uvloop/loop.c:160673:15
    #4 Server.close         uvloop/loop.c:161676:19

SUMMARY: AddressSanitizer: SEGV in PyType_IsSubtype

The sanitizer process exits with code 134 after ASan aborts.
UBSan did not emit a separate diagnostic before the ASan failure.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Server.close and Server._unref paths identified in uvloop/loop.c, then reproduce the failure with the Python snippet using Server(None). Trace the close path under ASan and verify that the reproducer raises a Python exception or otherwise completes without terminating the interpreter.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.