-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mono SIGABRT in System.Drawing.Common affecting some test runs #37838
Comments
Tagging subscribers to this area: @safern, @tannergooding |
This failure is still active in Mono. Will change this to a live issue. |
FYI @marek-safar |
Hmm, this looks like some interop corruption. @lambdageek / @vargaz could you please have a look |
Got it to fail in LLDB after a couple dozen iterations. Looks like this test fails runtime/src/libraries/System.Drawing.Common/tests/mono/System.Imaging/MetafileTest.cs Lines 375 to 413 in 6072e4d
It's dying in a call to My theory right now is that this is a use-after-free error - the test calls |
So then is it safe to say that this a bug in |
I think it's a bug in the test. It should dispose of |
Fixes dotnet#37838 Verified using libgdiplus built with mono/libgdiplus#671
Going to take another approach to this: refcount in managed and only dispose of the native metadata instance once all the graphics instances that take a reference to it are disposed. |
Checked on Windows both versions of the following work: using (Graphics g = fromImage (metafileImage)) {
... /* metafileImage.Dispose() here */
}
/* or metafileImage.Dispose() here */; On the other hand using (Graphics g = fromImage (mf))
using (Graphics g2 = fromImage (mf)) Throws an I'm not sure what the thread safety / locking situation should be. I'm assuming all the drawing stuff has to be on a single thread, but I haven't checked what happens on Windows. |
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
* [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 #37838 * Formatting fixes Co-authored-by: Santiago Fernandez Madero <safern@microsoft.com> * Address review feedback * Inilne unhelpful helper * formatting Co-authored-by: Santiago Fernandez Madero <safern@microsoft.com>
Fixed in: #43074 |
Affects clean test runs in #37536
AzDO run: https://dev.azure.com/dnceng/public/_build/results?buildId=681708&view=logs&j=c6f8dc49-92a1-5760-c098-ba97b8142bfb&t=22b0078b-0469-5ba6-8725-2121fdbae049&l=42
Test log: https://helix.dot.net/api/2019-06-17/jobs/73f57a06-eec2-4676-8076-302ccabec52f/workitems/System.Drawing.Common.Tests/console
Possibly related: #32827, #23784, but this issue appears to have a different termination code.
Runfo Tracking Issue: Assertions in System.Drawing.Common in Mono runs
Displaying 100 of 104 results
Build Result Summary
The text was updated successfully, but these errors were encountered: