From 39adc83c84ec09c8501ca980b8764beca01e18a8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 19 Oct 2020 19:48:03 -0500 Subject: [PATCH] [mono] Copy image data with AssemblyLoadContext.LoadFromStream (#43593) We don't actually pin the byte array, so it must be copied or it can be overwritten once we run a GC on the LOH. Fixes https://github.com/dotnet/runtime/issues/43402 Tested manually that it fixes the issue using the associated repro. This isn't really something that lends itself to a test, so that's the best I can do. Co-authored-by: Ryan Lucia --- src/mono/mono/metadata/appdomain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/mono/metadata/appdomain.c b/src/mono/mono/metadata/appdomain.c index 88686b6082811..6fbc8c99807e5 100644 --- a/src/mono/mono/metadata/appdomain.c +++ b/src/mono/mono/metadata/appdomain.c @@ -2821,7 +2821,7 @@ mono_alc_load_raw_bytes (MonoAssemblyLoadContext *alc, guint8 *assembly_data, gu { MonoAssembly *ass = NULL; MonoImageOpenStatus status; - MonoImage *image = mono_image_open_from_data_internal (alc, (char*)assembly_data, raw_assembly_len, FALSE, NULL, refonly, FALSE, NULL, NULL); + MonoImage *image = mono_image_open_from_data_internal (alc, (char*)assembly_data, raw_assembly_len, TRUE, NULL, refonly, FALSE, NULL, NULL); if (!image) { mono_error_set_bad_image_by_name (error, "In memory assembly", "0x%p", assembly_data);