[release/5.0] [mono] Copy image data with AssemblyLoadContext.LoadFromStream #43593
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 #43592 to release/5.0
/cc @CoffeeFlux
Customer Impact
Fix was prompted by a customer bug report at #43402
This bug will affect anyone using AssemblyLoadContext.LoadFromStream on wasm with enough other data in the LOH to trigger a GC, so the potential for others to hit this seems high in real applications despite it not showing up in testing.
Testing
Manually validated against the attached repro. Problem goes away even after 10 iterations, when previously the corruption would be evident on the first.
Risk
Low. This is just a one-line change that ensure we copy the data locally into non-managed memory. The copying functionality is hit regularly multiple other places in the runtime in addition to being fairly simple, so it is unlikely to cause problems. In a .NET 5 context, this fix is wasm-specific.