Skip to content
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

Fix pointer provenance in const serialize with zero sized type enum variants #3532

Merged
merged 1 commit into from
Jan 10, 2025

Conversation

ealmloff
Copy link
Member

@ealmloff ealmloff commented Jan 9, 2025

The new edition of rust includes extra checks for pointer providence that caught a bug in const serialize. When serializing an enum with zero sized type variants that still have an alignment of one, const serialize adds the alignment to the pointer before discarding the pointer. This PR fixes the issue by using wrapping_byte_add instead which allows the pointer to temporarily point to invalid memory as long as it is never read.

Note while the new release of miri catches this bug, I haven't seen it anywhere in production and if it were to appear it would likely be caught at compile time because const serialize is used in const code

@ealmloff ealmloff added bug Something isn't working const-serialize Related to the const serialize crate labels Jan 9, 2025
@ealmloff ealmloff changed the title Fix pointer provenance in const rust with zero sized type enum variants Fix pointer provenance in const serialize with zero sized type enum variants Jan 9, 2025
@jkelleyrtp jkelleyrtp merged commit 2924ec4 into DioxusLabs:main Jan 10, 2025
17 checks passed
@ealmloff ealmloff deleted the fix-const-serialize-provenance branch January 10, 2025 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working const-serialize Related to the const serialize crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants