[release/8.0-staging] Always zero-init if object contains pointers #100426
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.
Backport of #100265 to release/8.0-staging
Customer Impact
This was seen to cause failures due to heap corruption in local run-to-failure runs.
Using
GC.AllocateUninitializedArray()
API with reference-containing element types on NativeAOT would introduce silent heap corruptions and eventually cause a crash at the next full GC.Such failures would be extremely difficult to diagnose if happen in a real application.
Regression
Allowing reference types for pinned
GC.AllocateUninitializedArray()
was a new addition to the public API.The intended semantics of AllocateUninitializedArray with reference containing element types is to ignore the "Unintialized" part as GC heap does not expect uninitialized object references.
Historically, the check for this combination (reference-containing+uninitialized) was present in CoreCLR, but was not ported to NativeAOT as a part of the above change.
Testing
Regular tests + a test scenario that is sensitive to this scenario was added.
Risk
Low: This is matching the long existing behavior on CoreCLR.