Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Fix resource stream for collectible assemblies #22925

Merged
merged 2 commits into from
Mar 1, 2019

Conversation

janvorli
Copy link
Member

The GetManifestResourceStream was returning a stream that didn't keep
the underlying assembly alive. For collectible assemblies, that means
that an assembly could be collected and the stream still kept,
potentially reading garbage.

The fix is to create a new stream type that stores a reference to the
underlying assembly, thus ensuring the proper lifetime management.

I have also added a regression test that checks that the stream keeps the underlying assembly alive and it also checks that once the stream reference is gone, the assembly is collected.

The GetManifestResourceStream was returning a stream that didn't keep
the underlying assembly alive. For collectible assemblies, that means
that an assembly could be collected and the stream still kept,
potentially reading garbage.

The fix is to create a new stream type that stores a reference to the
underlying assembly, thus ensuring the proper lifetime management.
@janvorli janvorli added this to the 3.0 milestone Feb 28, 2019
@janvorli janvorli self-assigned this Feb 28, 2019
@janvorli janvorli requested a review from jkotas February 28, 2019 19:13
@janvorli
Copy link
Member Author

cc: @marek-safar

@@ -29,6 +29,16 @@ internal class RuntimeAssembly : Assembly

#endregion

private class ManifestResourceStream : UnmanagedMemoryStream
{
private RuntimeAssembly _manifestAssembly;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about releasing the reference on explicit Dispose?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explicit Dispose does not guarantee that nobody is accessing the memory anymore

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair enough, it'd have to invalidate the object state (maybe v2)

@@ -29,6 +29,16 @@ internal class RuntimeAssembly : Assembly

#endregion

private class ManifestResourceStream : UnmanagedMemoryStream

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should be sealed

@janvorli
Copy link
Member Author

@dotnet-bot test OSX10.12 x64 Checked Innerloop Build and Test please

@janvorli janvorli merged commit 452c40d into dotnet:master Mar 1, 2019
@janvorli janvorli deleted the fix-manifest-resource-stream branch March 1, 2019 11:10
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
* Fix resource stream for collectible assemblies

The GetManifestResourceStream was returning a stream that didn't keep
the underlying assembly alive. For collectible assemblies, that means
that an assembly could be collected and the stream still kept,
potentially reading garbage.

The fix is to create a new stream type that stores a reference to the
underlying assembly, thus ensuring the proper lifetime management.

* Make the new stream class sealed


Commit migrated from dotnet/coreclr@452c40d
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants