Skip to content
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

Closed
GrabYourPitchforks opened this issue Jun 13, 2020 · 10 comments
Closed
Assignees
Labels
area-System.Drawing blocking-clean-ci Blocking PR or rolling runs of 'runtime' or 'runtime-extra-platforms' runtime-mono specific to the Mono runtime test-run-core Test failures in .NET Core test runs
Milestone

Comments

@GrabYourPitchforks
Copy link
Member

GrabYourPitchforks commented Jun 13, 2020

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

===========================================================================================================
/private/tmp/helix/working/A83A0976/w/A92E096B/e /private/tmp/helix/working/A83A0976/w/A92E096B/e
  Discovering: System.Drawing.Common.Tests (method display = ClassAndMethod, method display options = None)
  Discovered:  System.Drawing.Common.Tests (found 1565 of 1967 test cases)
  Starting:    System.Drawing.Common.Tests (parallel test collections = on, max threads = 4)
    System.Drawing.Drawing2D.Tests.BlendTests.Ctor_LargeCount_ThrowsOutOfMemoryException [SKIP]
      Condition(s) not met: "IsNotIntMaxValueArrayIndexSupported"
    System.Drawing.Printing.Tests.PrintControllerTests.OnStartPage_InvokeWithPrint_ReturnsNull [SKIP]
      Condition(s) not met: "IsAnyInstalledPrinters"

=================================================================
	Native Crash Reporting
=================================================================
Got a segv while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

=================================================================
	Native stacktrace:
=================================================================
	0x10305ca56 - /private/tmp/helix/working/A83A0976/p/shared/Microsoft.NETCore.App/5.0.0/libcoreclr.dylib : mono_dump_native_crash_info
	0x102ffeae5 - /private/tmp/helix/working/A83A0976/p/shared/Microsoft.NETCore.App/5.0.0/libcoreclr.dylib : mono_handle_native_crash
	0x1030574c3 - /private/tmp/helix/working/A83A0976/p/shared/Microsoft.NETCore.App/5.0.0/libcoreclr.dylib : altstack_handle_and_restore
	0x7fff5d81d916 - /usr/lib/system/libsystem_c.dylib : fclose
	0x10771e7c0 - /usr/local/lib/libgdiplus.dylib : gdip_metafile_stop_recording
	0x10770ab5e - /usr/local/lib/libgdiplus.dylib : GdipDeleteGraphics
	0x108df9d35 - Unknown
	0x108ad8c91 - Unknown
	0x102f61f7e - /private/tmp/helix/working/A83A0976/p/shared/Microsoft.NETCore.App/5.0.0/libcoreclr.dylib : mono_jit_runtime_invoke
	0x10313acf8 - /private/tmp/helix/working/A83A0976/p/shared/Microsoft.NETCore.App/5.0.0/libcoreclr.dylib : mono_runtime_invoke_checked
	0x10314288c - /private/tmp/helix/working/A83A0976/p/shared/Microsoft.NETCore.App/5.0.0/libcoreclr.dylib : mono_runtime_try_invoke_array
	0x1030ec3e4 - /private/tmp/helix/working/A83A0976/p/shared/Microsoft.NETCore.App/5.0.0/libcoreclr.dylib : ves_icall_InternalInvoke
	0x1030f8484 - /private/tmp/helix/working/A83A0976/p/shared/Microsoft.NETCore.App/5.0.0/libcoreclr.dylib : ves_icall_InternalInvoke_raw

<snip>

----- end Wed Jun 10 17:22:30 PDT 2020 ----- exit code 134 ----------------------------------------------------------
exit code 134 means SIGABRT Abort. Managed or native assert, or runtime check such as heap corruption, caused call to abort(). Core dumped.

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

Build Definition Kind Run Name Console Core Dump Test Results Run Client
1067051 runtime PR 50479 net6.0-OSX-Debug-x64-Mono_release-OSX.1014.Amd64.Open console.log core dump runclient.py
1067051 runtime PR 50479 net6.0-OSX-Debug-x64-Mono_release-OSX.1015.Amd64.Open console.log core dump
1067051 runtime PR 50479 net6.0-Linux-Debug-x64-mono_interpreter_release-Debian.9.Amd64.Open console.log core dump
1067051 runtime PR 50479 net6.0-Linux-Debug-x64-Mono_release-(Centos.8.Amd64.Open)Ubuntu.1604.Amd64.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:centos-8-helix-20201229003624-c1bf759 console.log core dump
1067051 runtime PR 50479 net6.0-Linux-Debug-x64-Mono_release-RedHat.7.Amd64.Open console.log core dump
1067051 runtime PR 50479 net6.0-Linux-Debug-x64-Mono_release-(Debian.10.Amd64.Open)ubuntu.1604.amd64.open@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-10-helix-amd64-bfcd90a-20200121150006 console.log core dump
1067051 runtime PR 50479 net6.0-Linux-Debug-x64-Mono_release-Ubuntu.1604.Amd64.Open console.log core dump
1067051 runtime PR 50479 net6.0-Linux-Debug-x64-Mono_release-Ubuntu.1804.Amd64.Open console.log core dump
1067051 runtime PR 50479 net6.0-Linux-Debug-x64-Mono_release-SLES.15.Amd64.Open console.log core dump
1067051 runtime PR 50479 net6.0-Linux-Debug-x64-Mono_release-(Fedora.30.Amd64.Open)ubuntu.1604.amd64.open@mcr.microsoft.com/dotnet-buildtools/prereqs:fedora-30-helix-20200512010621-4f8cef7 console.log core dump
1067051 runtime PR 50479 net6.0-Linux-Debug-arm64-Mono_release-(Ubuntu.1804.ArmArch.Open)Ubuntu.1804.ArmArch.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-16.04-helix-arm64v8-20210106155927-56c6673 console.log core dump
1046026 runtime PR 49740 net6.0-Linux-Debug-x64-mono_interpreter_release-Debian.9.Amd64.Open console.log core dump
1046026 runtime PR 49740 net6.0-Linux-Debug-x64-Mono_release-(Centos.8.Amd64.Open)Ubuntu.1604.Amd64.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:centos-8-helix-20201229003624-c1bf759 console.log core dump
1046026 runtime PR 49740 net6.0-Linux-Debug-x64-Mono_release-RedHat.7.Amd64.Open console.log core dump runclient.py
1046026 runtime PR 49740 net6.0-Linux-Debug-x64-Mono_release-(Debian.10.Amd64.Open)ubuntu.1604.amd64.open@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-10-helix-amd64-bfcd90a-20200121150006 console.log core dump
1046026 runtime PR 49740 net6.0-Linux-Debug-x64-Mono_release-Ubuntu.1604.Amd64.Open console.log core dump
1046026 runtime PR 49740 net6.0-Linux-Debug-x64-Mono_release-Ubuntu.1804.Amd64.Open console.log core dump
1046026 runtime PR 49740 net6.0-Linux-Debug-x64-Mono_release-SLES.15.Amd64.Open console.log core dump
1046026 runtime PR 49740 net6.0-Linux-Debug-x64-Mono_release-(Fedora.30.Amd64.Open)ubuntu.1604.amd64.open@mcr.microsoft.com/dotnet-buildtools/prereqs:fedora-30-helix-20200512010621-4f8cef7 console.log core dump
1046026 runtime PR 49740 net6.0-Linux-Debug-arm64-Mono_release-(Ubuntu.1804.ArmArch.Open)Ubuntu.1804.ArmArch.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-16.04-helix-arm64v8-20210106155927-56c6673 console.log core dump
1046026 runtime PR 49740 net6.0-OSX-Debug-x64-Mono_release-OSX.1014.Amd64.Open console.log core dump
1046026 runtime PR 49740 net6.0-OSX-Debug-x64-Mono_release-OSX.1015.Amd64.Open console.log core dump
1038678 runtime Rolling net6.0-OSX-Release-x64-Mono_release-OSX.1013.Amd64.Open console.log runclient.py
1036531 runtime PR 48344 net5.0-OSX-Debug-x64-Mono_release-OSX.1013.Amd64.Open console.log runclient.py
1025834 runtime PR 49260 net6.0-OSX-Debug-x64-Mono_release-OSX.1014.Amd64.Open console.log
1025834 runtime PR 49260 net6.0-OSX-Debug-x64-Mono_release-OSX.1015.Amd64.Open console.log
1025834 runtime PR 49260 net6.0-Linux-Debug-x64-Mono_release-(Centos.8.Amd64.Open)Ubuntu.1604.Amd64.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:centos-8-helix-20201229003624-c1bf759 console.log core dump
1025834 runtime PR 49260 net6.0-Linux-Debug-x64-Mono_release-RedHat.7.Amd64.Open console.log core dump
1025834 runtime PR 49260 net6.0-Linux-Debug-x64-Mono_release-(Debian.10.Amd64.Open)ubuntu.1604.amd64.open@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-10-helix-amd64-bfcd90a-20200121150006 console.log core dump
1025834 runtime PR 49260 net6.0-Linux-Debug-x64-Mono_release-Ubuntu.1604.Amd64.Open console.log core dump
1025834 runtime PR 49260 net6.0-Linux-Debug-x64-Mono_release-Ubuntu.1804.Amd64.Open console.log core dump
1025834 runtime PR 49260 net6.0-Linux-Debug-x64-Mono_release-SLES.15.Amd64.Open console.log core dump
1025834 runtime PR 49260 net6.0-Linux-Debug-x64-Mono_release-(Fedora.30.Amd64.Open)ubuntu.1604.amd64.open@mcr.microsoft.com/dotnet-buildtools/prereqs:fedora-30-helix-20200512010621-4f8cef7 console.log core dump
1025834 runtime PR 49260 net6.0-windows-Debug-x64-Mono_release-Windows.81.Amd64.Open console.log
1025834 runtime PR 49260 net6.0-windows-Debug-x64-Mono_release-Windows.10.Amd64.Server19H1.ES.Open console.log
1020515 runtime Rolling net6.0-Linux-Release-x64-Mono_release-SLES.12.Amd64.Open console.log runclient.py
1019817 runtime PR 47864 net6.0-OSX-Debug-arm64-Mono_release-OSX.1100.ARM64.Open console.log core dump
1016780 runtime PR 48908 net6.0-OSX-Debug-x64-Mono_release-OSX.1014.Amd64.Open console.log core dump
1016780 runtime PR 48908 net6.0-OSX-Debug-x64-Mono_release-OSX.1015.Amd64.Open console.log core dump
1016780 runtime PR 48908 net6.0-Linux-Debug-x64-Mono_release-(Centos.8.Amd64.Open)Ubuntu.1604.Amd64.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:centos-8-helix-20201229003624-c1bf759 console.log core dump
1016780 runtime PR 48908 net6.0-Linux-Debug-x64-Mono_release-RedHat.7.Amd64.Open console.log core dump
1016780 runtime PR 48908 net6.0-Linux-Debug-x64-Mono_release-(Debian.10.Amd64.Open)ubuntu.1604.amd64.open@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-10-helix-amd64-bfcd90a-20200121150006 console.log core dump
1016780 runtime PR 48908 net6.0-Linux-Debug-x64-Mono_release-Ubuntu.1604.Amd64.Open console.log core dump
1016780 runtime PR 48908 net6.0-Linux-Debug-x64-Mono_release-Ubuntu.1804.Amd64.Open console.log core dump runclient.py
1016780 runtime PR 48908 net6.0-Linux-Debug-x64-Mono_release-SLES.15.Amd64.Open console.log core dump
1016780 runtime PR 48908 net6.0-Linux-Debug-x64-Mono_release-(Fedora.30.Amd64.Open)ubuntu.1604.amd64.open@mcr.microsoft.com/dotnet-buildtools/prereqs:fedora-30-helix-20200512010621-4f8cef7 console.log core dump
1016780 runtime PR 48908 net6.0-Linux-Debug-x64-mono_interpreter_release-Debian.9.Amd64.Open console.log core dump
1016780 runtime PR 48908 net6.0-Linux-Debug-arm64-Mono_release-(Ubuntu.1804.ArmArch.Open)Ubuntu.1804.ArmArch.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-16.04-helix-arm64v8-20210106155927-56c6673 console.log core dump
1016780 runtime PR 48908 net6.0-windows-Debug-x64-Mono_release-Windows.81.Amd64.Open console.log
1016780 runtime PR 48908 net6.0-windows-Debug-x64-Mono_release-Windows.10.Amd64.Server19H1.ES.Open console.log
994579 runtime PR 48286 net6.0-Linux-Debug-x64-Mono_release-(Centos.8.Amd64.Open)Ubuntu.1604.Amd64.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:centos-8-helix-20201229003624-c1bf759 console.log core dump
994579 runtime PR 48286 net6.0-Linux-Debug-x64-Mono_release-RedHat.7.Amd64.Open console.log core dump
994579 runtime PR 48286 net6.0-Linux-Debug-x64-Mono_release-(Debian.10.Amd64.Open)ubuntu.1604.amd64.open@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-10-helix-amd64-bfcd90a-20200121150006 console.log core dump
994579 runtime PR 48286 net6.0-Linux-Debug-x64-Mono_release-Ubuntu.1604.Amd64.Open console.log core dump
994579 runtime PR 48286 net6.0-Linux-Debug-x64-Mono_release-Ubuntu.1804.Amd64.Open console.log core dump
994579 runtime PR 48286 net6.0-Linux-Debug-x64-Mono_release-SLES.15.Amd64.Open console.log core dump
994579 runtime PR 48286 net6.0-Linux-Debug-x64-Mono_release-(Fedora.30.Amd64.Open)ubuntu.1604.amd64.open@mcr.microsoft.com/dotnet-buildtools/prereqs:fedora-30-helix-20200512010621-4f8cef7 console.log core dump
994579 runtime PR 48286 net6.0-OSX-Debug-x64-Mono_release-OSX.1014.Amd64.Open console.log
994579 runtime PR 48286 net6.0-OSX-Debug-x64-Mono_release-OSX.1015.Amd64.Open console.log core dump
994579 runtime PR 48286 net6.0-Linux-Debug-arm64-Mono_release-(Ubuntu.1804.ArmArch.Open)Ubuntu.1804.ArmArch.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-16.04-helix-arm64v8-20210106155927-56c6673 console.log core dump
994579 runtime PR 48286 net6.0-windows-Debug-x64-Mono_release-Windows.81.Amd64.Open console.log
994579 runtime PR 48286 net6.0-windows-Debug-x64-Mono_release-Windows.10.Amd64.Server19H1.ES.Open console.log
984199 runtime PR 48023 net6.0-OSX-Debug-x64-Mono_release-OSX.1014.Amd64.Open console.log core dump
984199 runtime PR 48023 net6.0-OSX-Debug-x64-Mono_release-OSX.1015.Amd64.Open console.log core dump
984199 runtime PR 48023 net6.0-Linux-Debug-x64-mono_interpreter_release-Debian.9.Amd64.Open console.log core dump
984199 runtime PR 48023 net6.0-Linux-Debug-x64-Mono_release-(Centos.8.Amd64.Open)Ubuntu.1604.Amd64.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:centos-8-helix-20201229003624-c1bf759 console.log core dump
984199 runtime PR 48023 net6.0-Linux-Debug-x64-Mono_release-RedHat.7.Amd64.Open console.log core dump
984199 runtime PR 48023 net6.0-Linux-Debug-x64-Mono_release-(Debian.10.Amd64.Open)ubuntu.1604.amd64.open@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-10-helix-amd64-bfcd90a-20200121150006 console.log core dump
984199 runtime PR 48023 net6.0-Linux-Debug-x64-Mono_release-Ubuntu.1604.Amd64.Open console.log core dump
984199 runtime PR 48023 net6.0-Linux-Debug-x64-Mono_release-Ubuntu.1804.Amd64.Open console.log core dump
984199 runtime PR 48023 net6.0-Linux-Debug-x64-Mono_release-SLES.15.Amd64.Open console.log core dump
984199 runtime PR 48023 net6.0-Linux-Debug-x64-Mono_release-(Fedora.30.Amd64.Open)ubuntu.1604.amd64.open@mcr.microsoft.com/dotnet-buildtools/prereqs:fedora-30-helix-20200512010621-4f8cef7 console.log core dump
984199 runtime PR 48023 net6.0-Linux-Debug-arm64-Mono_release-(Ubuntu.1804.ArmArch.Open)Ubuntu.1804.ArmArch.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-16.04-helix-arm64v8-20210106155927-56c6673 console.log core dump
980524 runtime PR 47864 net6.0-OSX-Debug-arm64-Mono_release-OSX.1100.ARM64.Open console.log core dump
980524 runtime PR 47864 net6.0-OSX-Debug-arm64-Mono_release-OSX.1100.ARM64.Open console.log core dump
980524 runtime PR 47864 net6.0-OSX-Debug-arm64-Mono_release-OSX.1100.ARM64.Open console.log core dump
974115 runtime PR 47526 net6.0-windows-Debug-x64-Mono_release-Windows.81.Amd64.Open console.log runclient.py
974115 runtime PR 47526 net6.0-windows-Debug-x64-Mono_release-Windows.10.Amd64.Server19H1.ES.Open console.log runclient.py
974055 runtime PR 47705 net6.0-windows-Debug-x64-Mono_release-Windows.81.Amd64.Open console.log runclient.py
974055 runtime PR 47705 net6.0-windows-Debug-x64-Mono_release-Windows.10.Amd64.Server19H1.ES.Open console.log runclient.py
973591 runtime PR 47705 net6.0-windows-Debug-x64-Mono_release-Windows.81.Amd64.Open console.log runclient.py
973591 runtime PR 47705 net6.0-windows-Debug-x64-Mono_release-Windows.10.Amd64.Server19H1.ES.Open console.log runclient.py
973591 runtime PR 47705 net6.0-windows-Debug-x64-Mono_release-Windows.81.Amd64.Open console.log runclient.py
973591 runtime PR 47705 net6.0-windows-Debug-x64-Mono_release-Windows.10.Amd64.Server19H1.ES.Open console.log runclient.py
970007 runtime PR 47526 net6.0-windows-Debug-x64-Mono_release-Windows.81.Amd64.Open console.log runclient.py
970007 runtime PR 47526 net6.0-windows-Debug-x64-Mono_release-Windows.10.Amd64.Server19H1.ES.Open console.log runclient.py
969744 runtime PR 47526 net6.0-windows-Debug-x64-Mono_release-Windows.81.Amd64.Open console.log runclient.py
969744 runtime PR 47526 net6.0-windows-Debug-x64-Mono_release-Windows.10.Amd64.Server19H1.ES.Open console.log runclient.py
968995 runtime PR 47526 net6.0-windows-Debug-x64-Mono_release-Windows.81.Amd64.Open console.log runclient.py
968995 runtime PR 47526 net6.0-windows-Debug-x64-Mono_release-Windows.10.Amd64.Server19H1.ES.Open console.log runclient.py
968596 runtime PR 47526 net6.0-windows-Debug-x64-Mono_release-Windows.81.Amd64.Open console.log runclient.py
968596 runtime PR 47526 net6.0-windows-Debug-x64-Mono_release-Windows.10.Amd64.Server19H1.ES.Open console.log runclient.py
968014 runtime PR 47526 net6.0-windows-Debug-x64-Mono_release-Windows.81.Amd64.Open console.log runclient.py
968014 runtime PR 47526 net6.0-windows-Debug-x64-Mono_release-Windows.10.Amd64.Server19H1.ES.Open console.log runclient.py
956492 runtime PR 47057 net6.0-Android-Release-arm64-Mono_Release-Windows.10.Amd64.Android.Open console.log runclient.py
956443 runtime PR 46964 net6.0-Android-Release-arm64-Mono_Release-Windows.10.Amd64.Android.Open console.log runclient.py
955610 runtime PR 47128 net6.0-Linux-Debug-arm64-Mono_release-(Ubuntu.1804.ArmArch.Open)Ubuntu.1804.ArmArch.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-16.04-helix-arm64v8-bfcd90a-20200127194925 console.log runclient.py
955610 runtime PR 47128 net6.0-Linux-Debug-x64-Mono_release-(Debian.10.Amd64.Open)ubuntu.1604.amd64.open@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-10-helix-amd64-bfcd90a-20200121150006 console.log runclient.py
955610 runtime PR 47128 net6.0-Linux-Debug-x64-Mono_release-Ubuntu.1804.Amd64.Open console.log
955610 runtime PR 47128 net6.0-Linux-Debug-x64-Mono_release-(Fedora.30.Amd64.Open)ubuntu.1604.amd64.open@mcr.microsoft.com/dotnet-buildtools/prereqs:fedora-30-helix-20200512010621-4f8cef7 console.log

Displaying 100 of 104 results

Build Result Summary

Day Hit Count Week Hit Count Month Hit Count
0 0 3
@GrabYourPitchforks GrabYourPitchforks added test-run-core Test failures in .NET Core test runs runtime-mono specific to the Mono runtime labels Jun 13, 2020
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.Drawing untriaged New issue has not been triaged by the area owner labels Jun 13, 2020
@ghost
Copy link

ghost commented Jun 13, 2020

Tagging subscribers to this area: @safern, @tannergooding
Notify danmosemsft if you want to be subscribed.

@safern safern added the blocking-clean-ci Blocking PR or rolling runs of 'runtime' or 'runtime-extra-platforms' label Jun 13, 2020
@tannergooding tannergooding removed the untriaged New issue has not been triaged by the area owner label Jul 8, 2020
@tannergooding tannergooding added this to the Future milestone Jul 8, 2020
@jaredpar
Copy link
Member

@jaredpar
Copy link
Member

FYI @marek-safar

@marek-safar
Copy link
Contributor

Hmm, this looks like some interop corruption. @lambdageek / @vargaz could you please have a look

@lambdageek
Copy link
Member

Got it to fail in LLDB after a couple dozen iterations. Looks like this test fails

[ConditionalFact(Helpers.IsDrawingSupported)]
public void Measure()
{
Font test_font = new Font(FontFamily.GenericMonospace, 12);
Metafile mf;
using (Bitmap bmp = new Bitmap(100, 100, PixelFormat.Format32bppArgb))
using (Graphics g = Graphics.FromImage(bmp))
{
IntPtr hdc = g.GetHdc();
try
{
mf = new Metafile(hdc, EmfType.EmfPlusOnly);
}
finally
{
g.ReleaseHdc(hdc);
}
}
using (Graphics g = Graphics.FromImage(mf))
{
string text = "this\nis a test";
CharacterRange[] ranges = new CharacterRange[2];
ranges[0] = new CharacterRange(0, 5);
ranges[1] = new CharacterRange(5, 9);
SizeF size = g.MeasureString(text, test_font);
Assert.False(size.IsEmpty);
StringFormat sf = new StringFormat();
sf.FormatFlags = StringFormatFlags.NoClip;
sf.SetMeasurableCharacterRanges(ranges);
RectangleF rect = new RectangleF(0, 0, size.Width, size.Height);
Region[] region = g.MeasureCharacterRanges(text, test_font, rect, sf);
Assert.Equal(2, region.Length);
mf.Dispose();
}
}

It's dying in a call to GdipDeleteGraphics which calls gdip_metafile_stop_recording (graphics->metafile).

My theory right now is that this is a use-after-free error - the test calls mf.Dispose() which calls gdip_metafile_dispose (metafile) which frees the memory, but graphics->metafile still points to it, so when we leave the using (Graphics g = Graphics.FromImage(mf)) scope, if someone else wrote over that memory which makes it look like graphics->metafile->recording is true, we crash.

@safern
Copy link
Member

safern commented Oct 1, 2020

So then is it safe to say that this a bug in libgdiplus that when we dispose the graphics object, it is not freeing, graphics->metafile?

@lambdageek
Copy link
Member

I think it's a bug in the test. It should dispose of mf outside the using, IMO

@lambdageek
Copy link
Member

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.

@lambdageek
Copy link
Member

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 OutOfMemoryException from the second line. So I believe it should be enough to just keep a reference from Metafile to Graphics that is initialized when the Graphics instance is created and only dispose of the Metafile when the Graphics instance is null.

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.

@lambdageek lambdageek self-assigned this Oct 6, 2020
lambdageek added a commit to lambdageek/runtime that referenced this issue Oct 6, 2020
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
lambdageek added a commit that referenced this issue Oct 8, 2020
* [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>
@safern
Copy link
Member

safern commented Oct 8, 2020

Fixed in: #43074

@safern safern closed this as completed Oct 8, 2020
@ghost ghost locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Drawing blocking-clean-ci Blocking PR or rolling runs of 'runtime' or 'runtime-extra-platforms' runtime-mono specific to the Mono runtime test-run-core Test failures in .NET Core test runs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants
@jaredpar @marek-safar @lambdageek @GrabYourPitchforks @tannergooding @safern @Dotnet-GitSync-Bot and others