forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[System.Drawing.Common] Work around libgdiplus use after free
On Windows, both of the following are legal Metafile mf = ... ; // get a metafile instance Graphics g = Graphics.FromImage(mf); g.Dispose(); mf.Dispose(); and Metafile mf = ... ; // get a metafile instance Graphics g = Graphics.FromImage(mf); mf.Dispose(); g.Dispose(); On Unix, libgdiplus has a use after free bug for the second form - the metafile native image is disposed, but the graphics instance still has a pointer to the memory that it will use during cleanup. If the memory is reused, the graphics instance will see garbage values and crash. The workaround is to add a MetadataHolder class and to transfer responsibility for disposing of the native image instance to it if the Metafile is disposed before the Graphics. Note that the following is not allowed (throws OutOfMemoryException on GDI+ on Windows), so there's only ever one instance of Graphics associated with a Metafile at a time. Graphics g = Graphics.FromImage(mf); Graphics g2 = Graphics.FromImage(mf); // throws Addresses dotnet#37838
- Loading branch information
1 parent
67a39a4
commit 48c2b9e
Showing
2 changed files
with
122 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters