Skip to content

Fix #74 - prevent borrowing 'static from non-'static #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

finnbear
Copy link
Member

@finnbear finnbear commented Jun 10, 2025

Fixes #74

This bug only affects you if you have a &'static _ field, such as &'static [u8] or &'static str, and you decode from a non-'static buffer. No other lifetimes are affected.

  • Adds a '__de: 'static bound for impl Decoder and impl Decode of any item with a &'static _ field, except PhantomData<&'static _>.
    • This skips impl Default and impl View, but I didn't think adding complexity was justified for no change in which user programs compile
  • Test that the bug no longer compiles
  • Test that it is still possible to decode a struct field of type &'static str from a 'static buffer
  • Test that it is still possible to decode a struct field of type PhantomData<&'static str> from a non-'static buffer
  • Test that it is still not possible to decode a struct field of type StaticStr (where type StaticStr = &'static str), even from a 'static buffer

Diff for a simple struct with one 'static field:
image

@finnbear finnbear requested a review from caibear June 10, 2025 12:34
@finnbear finnbear force-pushed the bugfix_74_unsound_static branch from b9d8886 to 3d852e9 Compare June 10, 2025 12:41
@finnbear finnbear force-pushed the bugfix_74_unsound_static branch from 3d852e9 to 89b2b26 Compare June 10, 2025 12:50
@finnbear finnbear changed the title Fix #74 - prevent borrowing 'static from non-'static. Fix #74 - prevent borrowing 'static from non-'static Jun 10, 2025
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.

Unsound decode for structs that expect a 'static lifetime
1 participant