Fix pointer provenance in const serialize with zero sized type enum variants #3532
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.
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