require capsule destructor closures to be 'static#6049
Merged
Conversation
Tpt
approved these changes
May 16, 2026
Contributor
Tpt
left a comment
There was a problem hiding this comment.
It's very likely that code which accidentally did this would crash in test suites, and the fact nobody reported this probably means it doesn't exist in the wild
Agreed. This is the kind of thing that is not checked at all by C/C++ and wouldn't be a CVE there.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
It turns out that while we have
T: 'staticrequirements on capsule constructors, for the variants which also acceptFtype parameters for destructors we lackF: 'static.This of course means that it's possible to define a destructor which captures data by-reference from the stack, which will most likely lead to instant segfault when the destructor runs on capsule cleanup.
I am undecided whether this is a severe enough issue that it warrants reporting to the Rust advisory-db; on the one hand it's very likely that code which accidentally did this would crash in test suites, and the fact nobody reported this probably means it doesn't exist in the wild. On the other hand, it is possible that there are accidental UAFs implemented in user code due to this gap. Opinions welcome.
(Credit to Codex security scanning for this discovery.)