Skip to content

gh-160535: Keep the ZstdDict alive until the zstd context is freed - #160536

Draft
gpshead wants to merge 1 commit into
python:mainfrom
gpshead:scanfix-zstd-ct3p1csj
Draft

gpshead wants to merge 1 commit into
python:mainfrom
gpshead:scanfix-zstd-ct3p1csj

Conversation

@gpshead

@gpshead gpshead commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

ZstdCompressor and ZstdDecompressor no longer have a tp_clear, and ZstdDict no longer exposes its cache of digested dictionaries to the garbage collector, so the dictionary and its ZSTD_CDict instances are only released in the deallocators, after ZSTD_freeCCtx()/ZSTD_freeDCtx() has stopped the worker threads. None of these objects can close a reference cycle on its own (the only route back is through a mutable object reachable from the zstd_dict tuple, which has its own tp_clear), so tp_traverse alone is enough. The decompressor has no worker threads and is changed only to keep the same ordering rule in both types. The new test runs in a subprocess because detecting the freed read depends on the allocator; it fails on Linux/glibc without the fix and may pass vacuously elsewhere.

Fixes #160535

ANT-2026-CT3P1CSJ

The garbage collector could release a ZstdCompressor's dictionary, or
the digested dictionaries cached by the ZstdDict, while worker threads
of the compression context were still reading them.  They are now only
released on deallocation, after the context has been freed.

ANT-2026-CT3P1CSJ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes sprint

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Crash when the GC collects a multi-threaded ZstdCompressor together with its ZstdDict

2 participants