Skip to content

[stable] Destabilize the Error::type_id function#16

Closed
c4rtune wants to merge 1 commit intomainfrom
pull/60785
Closed

[stable] Destabilize the Error::type_id function#16
c4rtune wants to merge 1 commit intomainfrom
pull/60785

Conversation

@c4rtune
Copy link
Copy Markdown
Owner

@c4rtune c4rtune commented Apr 23, 2026

This commit destabilizes the Error::type_id function in the standard library.
This does so by effectively reverting #58048, restoring the #[unstable]
attribute. The security mailing list has recently been notified of a
vulnerability relating to the stabilization of this function. First stabilized
in Rust 1.34.0, a stable function here allows users to implement a custom
return value for this function:

struct MyType;

impl Error for MyType {
fn type_id(&self) -> TypeId {
    // Enable safe casting to `String` by accident.
    TypeId::of::<String>()
}
}

This, when combined with the Error::downcast family of functions, allows
safely casting a type to any other type, clearly a memory safety issue! A
formal announcement has been made to the security mailing list as well as the blog

This commit simply destabilizes the Error::type_id which, although breaking
for users since Rust 1.34.0, is hoped to have little impact and has been deemed
sufficient to mitigate this issue for the stable channel. The long-term fate of
the Error::type_id API will be discussed at #60784.

@MonnetalX
Copy link
Copy Markdown

🔍 PR Link Analysis

🔗 Ranked Links

#1 the blog

🔍 The Error::type_id function is being reverted to unstable status due to a security vulnerability that allowed custom implementations to return arbitrary TypeId values.

#2 #58048

🔍 The Error::type_id function is being destabilized due to a security vulnerability that allows custom implementations to return arbitrary TypeId values, breaking type safety guarantees.

#3 #60784

🔍 The Error::type_id function is being destabilized due to a security vulnerability that allows custom implementations to return arbitrary TypeId values, breaking type safety guarantees.

#4 security mailing list

🔍 The Error::type_id function was stabilized in Rust 1.34.0, but a security vulnerability has been identified because its stable status allows custom implementations that can return arbitrary TypeId values.

@c4rtune c4rtune closed this Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants