Skip to content

Heap corruption when Target OS is set #100544

@uler3161

Description

@uler3161

Description

I have an ASP.NET Core application, but I don't think it's specific to ASP.NET Core. This app interfaces with GStreamer using GStreamer-Sharp that I've built from source (upgraded with upgrade-assistant and built with .NET 8.0). I have all of this working correctly when I run it from Visual Studio 2022. Target framework for the web app is .NET 8.0.

I have a QA environment set up with Jenkins. It uses msbuild to build and deploy the app to IIS (version 10 on Server 2019). I found that the app worked fine until I tried to run GStreamer functionality. It would kill w3wp.exe with a 0xc0000374 code in ntdll.dll. Apparently that means heap corruption.

Moving back to my development machine, after some experimentation changing settings in VS, I tested the following:

Target OS Target OS Version Supported OS Version Configuration Platform Result
(None) Debug Any CPU Works
(None) Release Any CPU Works
Windows 7.0 7.0 Debug Any CPU Crashes
Windows 7.0 7.0 Release Any CPU Crashes
Windows 10.0.17763.0 10.0.17763.0 Debug Any CPU Crashes
Windows 10.0.17763.0 10.0.17763.0 Release Any CPU Crashes

Since it appears to be related to GStreamer, I tried playing around with Target OS settings when building GStreamer-Sharp, but that didn't seem to matter. Plus, since it works fine when Target OS is (None), I'm not really sure that's where the problem lies.

I'm making an assumption here that whatever msbuild is doing in my Jenkins deploy is related to the Target OS setting, but I don't know for sure. So perhaps there are two causes here resulting in the same problem. Here is basically what my Jenkins setup is doing:

msbuild.exe path\to\solution.sln /nologo /nr:false /p:platform="Any CPU" /p:configuration="release" /t:clean;restore;rebuild /p:TargetFramework=net8.0
msbuild.exe path\to\webapp.csproj /p:WebPublishMethod=MSDeploy /p:Password=$PASSWORD /p:Username=$USERNAME /p:AllowUntrustedCertificate=true /p:DeployOnBuild=true /p:LaunchSiteAfterPublish=false /p:VisualStudioVersion=17.0 /p:LastUsedBuildConfiguration=Release /p:LastUsedPlatform="Any CPU" /p:SiteUrlToLaunchAfterPublish=https://myserver /p:ExcludeApp_Data=false /p:MSDeployServiceURL=myserver /p:DeployIisAppPath=myapp /p:SkipExtraFilesOnServer=true /p:MSDeployPublishMethod=WMSVC /p:EnableMSDeployBackup=true /p:EnableMsDeployAppOffline=true /p:TargetFramework=net8.0

Reproduction Steps

I've attempted to put together a smaller example program, but haven't been able to replicate the problem. It may be possible to provide our entire application if need be. I also have a dump generated with DebugDiag that I can send along if desired.

Expected behavior

No heap corruption regardless of whether I specify Target OS.

Actual behavior

I collected a dump with DebugDiag. The Analysis pointed this out:

***********************
*  EXCEPTION DETAILS  *
***********************

DetailID = 1
	Count:    1
	Exception #:  0X80000003
	Stack:        
		ntdll!RtlReportCriticalFailure+0x56
		ntdll!RtlpHeapHandleError+0x12
		ntdll!RtlpHpHeapHandleError+0x7a
		ntdll!RtlpLogHeapFailure+0x45
		ntdll!RtlpFreeHeapInternal+0x4e0
		ntdll!RtlFreeHeap+0x51
		ucrtbase!_free_base+0x1b
		gstsdp_1_0_0!gst_sdp_message_free+0x1b
		gstwebrtc_1_0_0!gst_webrtc_session_description_free+0x18
		gobject_2_0_0!g_value_unset+0x29
		gstreamer_1_0_0!gst_structure_free+0x60
		gstreamer_1_0_0!gst_promise_expire+0x163
		gstreamer_1_0_0!gst_mini_object_unref+0x307
		gstwebrtc!gst_plugin_webrtc_register+0x9817
		glib_2_0_0!g_list_sort_with_data+0x231
		glib_2_0_0!g_source_destroy+0xdc
		glib_2_0_0!g_main_depth+0x1ce
		glib_2_0_0!g_main_context_is_owner+0x20a
		glib_2_0_0!g_main_loop_run+0x133
		gstwebrtc!gst_plugin_webrtc_register+0x9fed
		glib_2_0_0!g_thread_new+0x1a2
		glib_2_0_0!g_rw_lock_writer_unlock+0x4a7
		ucrtbase!thread_start<unsigned int (__cdecl*)(void *),1>+0x42
		KERNEL32!BaseThreadInitThunk+0x14
		ntdll!RtlUserThreadStart+0x21


DetailID = 2
	Count:    2
	Exception #:  0XC0000374
	Stack:        
		ntdll!RtlReportFatalFailure+0x9
		ntdll!RtlReportCriticalFailure+0x97
		ntdll!RtlpHeapHandleError+0x12
		ntdll!RtlpHpHeapHandleError+0x7a
		ntdll!RtlpLogHeapFailure+0x45
		ntdll!RtlpFreeHeapInternal+0x4e0
		ntdll!RtlFreeHeap+0x51
		ucrtbase!_free_base+0x1b
		gstsdp_1_0_0!gst_sdp_message_free+0x1b
		gstwebrtc_1_0_0!gst_webrtc_session_description_free+0x18
		gobject_2_0_0!g_value_unset+0x29
		gstreamer_1_0_0!gst_structure_free+0x60
		gstreamer_1_0_0!gst_promise_expire+0x163
		gstreamer_1_0_0!gst_mini_object_unref+0x307
		gstwebrtc!gst_plugin_webrtc_register+0x9817
		glib_2_0_0!g_list_sort_with_data+0x231
		glib_2_0_0!g_source_destroy+0xdc
		glib_2_0_0!g_main_depth+0x1ce
		glib_2_0_0!g_main_context_is_owner+0x20a
		glib_2_0_0!g_main_loop_run+0x133
		gstwebrtc!gst_plugin_webrtc_register+0x9fed
		glib_2_0_0!g_thread_new+0x1a2
		glib_2_0_0!g_rw_lock_writer_unlock+0x4a7
		ucrtbase!thread_start<unsigned int (__cdecl*)(void *),1>+0x42
		KERNEL32!BaseThreadInitThunk+0x14
		ntdll!RtlUserThreadStart+0x21  

Regression?

The app did work previously. I believe with .NET 6.0. If need be, I can try to build an older copy of the code and re-test, but it will take some effort.

Known Workarounds

No response

Configuration

.NET 8.0.
Development machine is Windows 10 x64, Version 22H2, OS build 19045.4170
IIS machine is Server 2019 Standard, Version 1809, OS build 17763.5576
Jenkins machine is Server 2019 Standard, Version 1809, OS build 17763.2090

Other information

I'm curious if #100426 is related.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions