[release/5.0] Remove the sealed blittable layoutclass correctness fix because of backcompat. #54244
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.
Port of #54235
Customer Impact
Copying data for a non-sealed blittable layout class instead of pinning leads to a use-after-free bug of code on the native heap in NAudio on .NET 5.0.7.
NAudio pins the layoutclass object in managed code and uses the same memory address across multiple native calls. When the fix in #50882 changed the layoutclass marshaller to have some extra safety and not pass non-sealed blittable layout classes by pinning and instead allocate memory and copy, the assumption NAudio made around the object's native representation's address being constant while the managed object is pinned with a pinned GC handle became untrue.
Testing
Testing added in PR.
Fix validated by users.
Risk
Low. This puts our behavior fully 100% in line with 3.1 for our layout class marshalling with no observable differences in behavior for any scenario we know about. I know I said the same thing in #50882, but at the time I did not realize that there was a mechanism to become dependent on the pinning optimization occurring outside of the data marshalling around the call (which #50882 included compat behavior to preserve).
Regression
This is a regression introduced in #50882