dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.27k stars 4.73k forks source link

[dotnet-sdk-9.0.100-preview.2.24113.6] SharpScss.dll causes application crash when converting scss to css #98646

Closed Junjun-zhao closed 8 months ago

Junjun-zhao commented 8 months ago

Description

When running 3rd party application with the lastest .NET 9 build, it stops working after accessing page. After investigation, we found it is caused by SharpScss.dll when converting scss to css. The exception from Visual Studio output window is: "Exception thrown: 'SharpScss.ScssException' in SharpScss.dll".

Reproduction Steps

Minimal Repro steps (Demo attached): ConsoleDemo.zip

The machine has dotnet-sdk-9.0.100-preview.2.24113.6 installed.

  1. Create a new console project.

  2. Install SharpScss nuget package.

  3. Copy the following code to Program.cs:

using SharpScss;
var result = Scss.ConvertToCss(@"@import ""foo"";", new ScssOptions()
{
    OutputStyle = ScssOutputStyle.Compressed,
    InputFile = "test.scss",
    TryImport = (ref string file, string path, out string scss, out string map) =>
    {
        scss = "div {color: #FFF;}";
        map = null;
        return true;
    }
});
var css = result.Css.Trim();
Console.WriteLine(css);
Console.ReadKey();
  1. Build the app.

  2. Change the runtime.config file to let the app run against with dotnet-sdk-9.0.100-preview.2.24113.6.

 "framework": {
      "name": "Microsoft.NETCore.App",
      "version": "9.0.0-preview.2.24112.33"
    }
  1. Launch the app.

Expected behavior

Launch successfully with converted css output in command window: image

Actual behavior

App crashed with stop working prompt window.

Regression?

Yes Verify Scenarios:

  1. Windows10 21h2 x64 + dotnet-sdk-7.0.406-win-x64: Pass
  2. Windows10 21h2 x64 + dotnet-sdk-9.0.100-preview.1.24101.2: Pass
  3. Windows10 21h2 x64 + dotnet-sdk-9.0.100-preview.2.24110.2: Fail
  4. Windows10 21h2 x64 + dotnet-sdk-9.0.100-preview.2.24116.21: Fail

Known Workarounds

No response

Configuration

Application Name: Smartstore OS: Windows 10 21H2 CPU: X64 .NET Build Number: dotnet-sdk-9.0.100-preview.2.24113.6 App & Source Location: Checking at https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1970756 Github Link: https://github.com/smartstore/Smartstore

Other information

Findings: When using Windbg to run and analyze the application, we get below information:

# Child-SP          RetAddr               Call Site
00 00000042`bf97e070 00007ffe`eed38092     ntdll!RtlReportCriticalFailure+0x56 [minkernel\ntos\rtl\rtlutil.c @ 201]
01 00000042`bf97e160 00007ffe`eed3837a     ntdll!RtlpHeapHandleError+0x12 [minkernel\ntos\rtl\heaplog.c @ 352]
02 00000042`bf97e190 00007ffe`eed3e001     ntdll!RtlpHpHeapHandleError+0x7a [minkernel\ntos\rtl\heaplog.c @ 678]
03 00000042`bf97e1c0 00007ffe`eec55b43     ntdll!RtlpLogHeapFailure+0x45 [minkernel\ntos\rtl\heaplibcommon.c @ 158]
04 (Inline Function) --------`--------     ntdll!RtlpProbeUserBufferUnsafe+0x26 [minkernel\ntos\rtl\heappriv.h @ 2786]
05 (Inline Function) --------`--------     ntdll!RtlpProbeUserBuffer+0x30 [minkernel\ntos\rtl\heappriv.h @ 2829]
06 00000042`bf97e1f0 00007ffe`eec547b1     ntdll!RtlpFreeHeapInternal+0x433 [minkernel\ntos\rtl\heap.c @ 2596]
07 (Inline Function) --------`--------     ntdll!RtlpHpHeapFreeRedirectLayer+0x1a [minkernel\ntos\rtl\heappublic.c @ 243]
08 00000042`bf97e2b0 00007ffe`94f98918     ntdll!RtlFreeHeap+0x51 [minkernel\ntos\rtl\heappublic.c @ 357]
09 00000042`bf97e2f0 00007ffe`94ea5312     libsass!sass2scss_version+0x47128
0a 00000042`bf97e320 00007ffe`94ea444e     libsass!sass_option_get_source_comments+0x8262
0b 00000042`bf97e360 00007ffe`94f4a940     libsass!sass_option_get_source_comments+0x739e
0c 00000042`bf97e390 00007ffe`2ea67b88     libsass!sass_delete_compiler+0x20
0d 00000042`bf97e3c0 00007ffe`2ea64063     SharpScss!ILStubClass.IL_STUB_PInvoke(Sass_Compiler)+0x68
0e 00000042`bf97e480 00007ffe`2ea63f81     SharpScss!SharpScss.Scss.FromCore+0x503
0f 00000042`bf97e4f0 00007ffe`2ea63a92     SharpScss!SharpScss.Scss.FromCore+0x421
10 00000042`bf97e680 00007ffe`2ea636fa     SharpScss!SharpScss.Scss.ConvertToCss+0x92
11 00000042`bf97e6c0 00007ffe`8e5d70b3     ConsoleApp6!Program.<Main>$+0x19a [E:\AppsSourceCode\ConsoleApp6\ConsoleApp6\Program.cs @ 3]
12 00000042`bf97e790 00007ffe`8e4fa07e     coreclr!CallDescrWorkerInternal+0x83 [D:\a\_work\1\s\src\coreclr\vm\amd64\CallDescrWorkerAMD64.asm @ 100]
13 00000042`bf97e7d0 00007ffe`8e58cfd4     coreclr!MethodDescCallSite::CallTargetWorker+0x21a [D:\a\_work\1\s\src\coreclr\vm\callhelpers.cpp @ 563]
14 (Inline Function) --------`--------     coreclr!MethodDescCallSite::Call+0xb [D:\a\_work\1\s\src\coreclr\vm\callhelpers.h @ 458]
15 00000042`bf97e910 00007ffe`8e58cd8e     coreclr!RunMainInternal+0x11c [D:\a\_work\1\s\src\coreclr\vm\assembly.cpp @ 1249]
16 00000042`bf97ea30 00007ffe`8e58c486     coreclr!RunMain+0xd2 [D:\a\_work\1\s\src\coreclr\vm\assembly.cpp @ 1320]
17 00000042`bf97eae0 00007ffe`8e58bd6f     coreclr!Assembly::ExecuteMainMethod+0x1ae [D:\a\_work\1\s\src\coreclr\vm\assembly.cpp @ 1449]
18 00000042`bf97edb0 00007ffe`8e59fed8     coreclr!CorHost2::ExecuteAssembly+0x21f [D:\a\_work\1\s\src\coreclr\vm\corhost.cpp @ 349]
19 00000042`bf97ef30 00007ffe`bc4ef106     coreclr!coreclr_execute_assembly+0xd8 [D:\a\_work\1\s\src\coreclr\dlls\mscoree\exports.cpp @ 494]
1a (Inline Function) --------`--------     hostpolicy!coreclr_t::execute_assembly+0x2a [D:\a\_work\1\s\src\native\corehost\hostpolicy\coreclr.cpp @ 108]
1b 00000042`bf97efd0 00007ffe`bc4ef3ec     hostpolicy!run_app_for_context+0x596 [D:\a\_work\1\s\src\native\corehost\hostpolicy\hostpolicy.cpp @ 256]
1c 00000042`bf97f160 00007ffe`bc4efd2a     hostpolicy!run_app+0x3c [D:\a\_work\1\s\src\native\corehost\hostpolicy\hostpolicy.cpp @ 285]
1d 00000042`bf97f1a0 00007ffe`bc8db2c9     hostpolicy!corehost_main+0x15a [D:\a\_work\1\s\src\native\corehost\hostpolicy\hostpolicy.cpp @ 426]
1e 00000042`bf97f2a0 00007ffe`bc8ddd66     hostfxr!execute_app+0x2e9 [D:\a\_work\1\s\src\native\corehost\fxr\fx_muxer.cpp @ 145]
1f 00000042`bf97f3a0 00007ffe`bc8dffec     hostfxr!`anonymous namespace'::read_config_and_execute+0xa6 [D:\a\_work\1\s\src\native\corehost\fxr\fx_muxer.cpp @ 532]
20 00000042`bf97f490 00007ffe`bc8de344     hostfxr!fx_muxer_t::handle_exec_host_command+0x16c [D:\a\_work\1\s\src\native\corehost\fxr\fx_muxer.cpp @ 1007]
21 00000042`bf97f540 00007ffe`bc8d82a0     hostfxr!fx_muxer_t::execute+0x494 [D:\a\_work\1\s\src\native\corehost\fxr\fx_muxer.cpp @ 578]
22 00000042`bf97f680 00007ff7`79b4f9d8     hostfxr!hostfxr_main_startupinfo+0xa0 [D:\a\_work\1\s\src\native\corehost\fxr\hostfxr.cpp @ 62]
23 00000042`bf97f780 00007ff7`79b4fde6     apphost!exe_start+0x878 [D:\a\_work\1\s\src\native\corehost\corehost.cpp @ 240]
24 00000042`bf97f950 00007ff7`79b51328     apphost!wmain+0x146 [D:\a\_work\1\s\src\native\corehost\corehost.cpp @ 311]
25 (Inline Function) --------`--------     apphost!invoke_main+0x22 [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 90]
26 00000042`bf97f9c0 00007ffe`ed367344     apphost!__scrt_common_main_seh+0x10c [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 288]
27 00000042`bf97fa00 00007ffe`eec826b1     KERNEL32!BaseThreadInitThunk+0x14 [clientcore\base\win32\client\thread.c @ 64]
28 00000042`bf97fa30 00000000`00000000     ntdll!RtlUserThreadStart+0x21 [minkernel\ntdll\rtlstrt.c @ 1153]

Dotnet Info:

.NET SDK:
 Version:           9.0.100-preview.2.24113.6
 Commit:            94def2ee6c
 Workload version:  9.0.100-manifests.e6972cff
Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19045
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\9.0.100-preview.2.24113.6\
.NET workloads installed:
 [wasm-tools]
   Installation Source: VS 17.8.34601.278
   Manifest Version:    9.0.0-preview.2.24112.33/9.0.100-preview.2
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100-preview.2\microsoft.net.workload.mono.toolchain.current\9.0.0-preview.2.24112.33\WorkloadManifest.json
   Install Type:              Msi
Host:
  Version:      9.0.0-preview.2.24112.33
  Architecture: x64
  Commit:       6299d3e88f
.NET SDKs installed:
  9.0.100-preview.2.24113.6 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
  Microsoft.AspNetCore.App 9.0.0-preview.2.24112.25 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 9.0.0-preview.2.24112.33 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 9.0.0-preview.2.24112.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

@dotnet-actwx-bot @dotnet/compat

jeffschwMSFT commented 8 months ago

please follow-up with the maintainers of SharpScss. the stack above indicates native heap corruption within that component.

ghost commented 8 months ago

This issue has been marked needs-author-action and may be missing some important information.

ghost commented 8 months ago

Tagging subscribers to this area: @dotnet/area-meta See info in area-owners.md if you want to be subscribed.

Issue Details
### Description When running 3rd party application with the lastest .NET 9 build, it stops working after accessing page. After investigation, we found it is caused by SharpScss.dll when converting scss to css. The exception from Visual Studio output window is: "Exception thrown: 'SharpScss.ScssException' in SharpScss.dll". ### Reproduction Steps **Minimal Repro steps (Demo attached):** [ConsoleDemo.zip](https://github.com/dotnet/runtime/files/14327789/ConsoleDemo.zip) **The machine has dotnet-sdk-9.0.100-preview.2.24113.6 installed.** 1. Create a new console project. 2. Install SharpScss nuget package. 3. Copy the following code to Program.cs: ``` using SharpScss; var result = Scss.ConvertToCss(@"@import ""foo"";", new ScssOptions() { OutputStyle = ScssOutputStyle.Compressed, InputFile = "test.scss", TryImport = (ref string file, string path, out string scss, out string map) => { scss = "div {color: #FFF;}"; map = null; return true; } }); var css = result.Css.Trim(); Console.WriteLine(css); Console.ReadKey(); ``` 4. Build the app. 5. Change the runtime.config file to let the app run against with dotnet-sdk-9.0.100-preview.2.24113.6. ``` "framework": { "name": "Microsoft.NETCore.App", "version": "9.0.0-preview.2.24112.33" } ``` 6. Launch the app. ### Expected behavior Launch successfully with converted css output in command window: ![image](https://github.com/dotnet/runtime/assets/83067197/a2a5fa6c-561e-40fd-a688-48f4be725fe9) ### Actual behavior App crashed with stop working prompt window. ### Regression? Yes **Verify Scenarios:** 1. Windows10 21h2 x64 + dotnet-sdk-7.0.406-win-x64: Pass 2. Windows10 21h2 x64 + dotnet-sdk-9.0.100-preview.1.24101.2: Pass 3. Windows10 21h2 x64 + dotnet-sdk-9.0.100-preview.2.24110.2: Fail 4. Windows10 21h2 x64 + dotnet-sdk-9.0.100-preview.2.24116.21: Fail ### Known Workarounds _No response_ ### Configuration **Application Name**: Smartstore **OS**: Windows 10 21H2 **CPU**: X64 **.NET Build Number**: dotnet-sdk-9.0.100-preview.2.24113.6 **App & Source Location**: Checking at https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1970756 **Github Link**: https://github.com/smartstore/Smartstore ### Other information **Findings:** When using Windbg to run and analyze the application, we get below information: ``` # Child-SP RetAddr Call Site 00 00000042`bf97e070 00007ffe`eed38092 ntdll!RtlReportCriticalFailure+0x56 [minkernel\ntos\rtl\rtlutil.c @ 201] 01 00000042`bf97e160 00007ffe`eed3837a ntdll!RtlpHeapHandleError+0x12 [minkernel\ntos\rtl\heaplog.c @ 352] 02 00000042`bf97e190 00007ffe`eed3e001 ntdll!RtlpHpHeapHandleError+0x7a [minkernel\ntos\rtl\heaplog.c @ 678] 03 00000042`bf97e1c0 00007ffe`eec55b43 ntdll!RtlpLogHeapFailure+0x45 [minkernel\ntos\rtl\heaplibcommon.c @ 158] 04 (Inline Function) --------`-------- ntdll!RtlpProbeUserBufferUnsafe+0x26 [minkernel\ntos\rtl\heappriv.h @ 2786] 05 (Inline Function) --------`-------- ntdll!RtlpProbeUserBuffer+0x30 [minkernel\ntos\rtl\heappriv.h @ 2829] 06 00000042`bf97e1f0 00007ffe`eec547b1 ntdll!RtlpFreeHeapInternal+0x433 [minkernel\ntos\rtl\heap.c @ 2596] 07 (Inline Function) --------`-------- ntdll!RtlpHpHeapFreeRedirectLayer+0x1a [minkernel\ntos\rtl\heappublic.c @ 243] 08 00000042`bf97e2b0 00007ffe`94f98918 ntdll!RtlFreeHeap+0x51 [minkernel\ntos\rtl\heappublic.c @ 357] 09 00000042`bf97e2f0 00007ffe`94ea5312 libsass!sass2scss_version+0x47128 0a 00000042`bf97e320 00007ffe`94ea444e libsass!sass_option_get_source_comments+0x8262 0b 00000042`bf97e360 00007ffe`94f4a940 libsass!sass_option_get_source_comments+0x739e 0c 00000042`bf97e390 00007ffe`2ea67b88 libsass!sass_delete_compiler+0x20 0d 00000042`bf97e3c0 00007ffe`2ea64063 SharpScss!ILStubClass.IL_STUB_PInvoke(Sass_Compiler)+0x68 0e 00000042`bf97e480 00007ffe`2ea63f81 SharpScss!SharpScss.Scss.FromCore+0x503 0f 00000042`bf97e4f0 00007ffe`2ea63a92 SharpScss!SharpScss.Scss.FromCore+0x421 10 00000042`bf97e680 00007ffe`2ea636fa SharpScss!SharpScss.Scss.ConvertToCss+0x92 11 00000042`bf97e6c0 00007ffe`8e5d70b3 ConsoleApp6!Program.
$+0x19a [E:\AppsSourceCode\ConsoleApp6\ConsoleApp6\Program.cs @ 3] 12 00000042`bf97e790 00007ffe`8e4fa07e coreclr!CallDescrWorkerInternal+0x83 [D:\a\_work\1\s\src\coreclr\vm\amd64\CallDescrWorkerAMD64.asm @ 100] 13 00000042`bf97e7d0 00007ffe`8e58cfd4 coreclr!MethodDescCallSite::CallTargetWorker+0x21a [D:\a\_work\1\s\src\coreclr\vm\callhelpers.cpp @ 563] 14 (Inline Function) --------`-------- coreclr!MethodDescCallSite::Call+0xb [D:\a\_work\1\s\src\coreclr\vm\callhelpers.h @ 458] 15 00000042`bf97e910 00007ffe`8e58cd8e coreclr!RunMainInternal+0x11c [D:\a\_work\1\s\src\coreclr\vm\assembly.cpp @ 1249] 16 00000042`bf97ea30 00007ffe`8e58c486 coreclr!RunMain+0xd2 [D:\a\_work\1\s\src\coreclr\vm\assembly.cpp @ 1320] 17 00000042`bf97eae0 00007ffe`8e58bd6f coreclr!Assembly::ExecuteMainMethod+0x1ae [D:\a\_work\1\s\src\coreclr\vm\assembly.cpp @ 1449] 18 00000042`bf97edb0 00007ffe`8e59fed8 coreclr!CorHost2::ExecuteAssembly+0x21f [D:\a\_work\1\s\src\coreclr\vm\corhost.cpp @ 349] 19 00000042`bf97ef30 00007ffe`bc4ef106 coreclr!coreclr_execute_assembly+0xd8 [D:\a\_work\1\s\src\coreclr\dlls\mscoree\exports.cpp @ 494] 1a (Inline Function) --------`-------- hostpolicy!coreclr_t::execute_assembly+0x2a [D:\a\_work\1\s\src\native\corehost\hostpolicy\coreclr.cpp @ 108] 1b 00000042`bf97efd0 00007ffe`bc4ef3ec hostpolicy!run_app_for_context+0x596 [D:\a\_work\1\s\src\native\corehost\hostpolicy\hostpolicy.cpp @ 256] 1c 00000042`bf97f160 00007ffe`bc4efd2a hostpolicy!run_app+0x3c [D:\a\_work\1\s\src\native\corehost\hostpolicy\hostpolicy.cpp @ 285] 1d 00000042`bf97f1a0 00007ffe`bc8db2c9 hostpolicy!corehost_main+0x15a [D:\a\_work\1\s\src\native\corehost\hostpolicy\hostpolicy.cpp @ 426] 1e 00000042`bf97f2a0 00007ffe`bc8ddd66 hostfxr!execute_app+0x2e9 [D:\a\_work\1\s\src\native\corehost\fxr\fx_muxer.cpp @ 145] 1f 00000042`bf97f3a0 00007ffe`bc8dffec hostfxr!`anonymous namespace'::read_config_and_execute+0xa6 [D:\a\_work\1\s\src\native\corehost\fxr\fx_muxer.cpp @ 532] 20 00000042`bf97f490 00007ffe`bc8de344 hostfxr!fx_muxer_t::handle_exec_host_command+0x16c [D:\a\_work\1\s\src\native\corehost\fxr\fx_muxer.cpp @ 1007] 21 00000042`bf97f540 00007ffe`bc8d82a0 hostfxr!fx_muxer_t::execute+0x494 [D:\a\_work\1\s\src\native\corehost\fxr\fx_muxer.cpp @ 578] 22 00000042`bf97f680 00007ff7`79b4f9d8 hostfxr!hostfxr_main_startupinfo+0xa0 [D:\a\_work\1\s\src\native\corehost\fxr\hostfxr.cpp @ 62] 23 00000042`bf97f780 00007ff7`79b4fde6 apphost!exe_start+0x878 [D:\a\_work\1\s\src\native\corehost\corehost.cpp @ 240] 24 00000042`bf97f950 00007ff7`79b51328 apphost!wmain+0x146 [D:\a\_work\1\s\src\native\corehost\corehost.cpp @ 311] 25 (Inline Function) --------`-------- apphost!invoke_main+0x22 [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 90] 26 00000042`bf97f9c0 00007ffe`ed367344 apphost!__scrt_common_main_seh+0x10c [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 288] 27 00000042`bf97fa00 00007ffe`eec826b1 KERNEL32!BaseThreadInitThunk+0x14 [clientcore\base\win32\client\thread.c @ 64] 28 00000042`bf97fa30 00000000`00000000 ntdll!RtlUserThreadStart+0x21 [minkernel\ntdll\rtlstrt.c @ 1153] ``` **Dotnet Info**: ``` .NET SDK: Version: 9.0.100-preview.2.24113.6 Commit: 94def2ee6c Workload version: 9.0.100-manifests.e6972cff Runtime Environment: OS Name: Windows OS Version: 10.0.19045 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\9.0.100-preview.2.24113.6\ .NET workloads installed: [wasm-tools] Installation Source: VS 17.8.34601.278 Manifest Version: 9.0.0-preview.2.24112.33/9.0.100-preview.2 Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100-preview.2\microsoft.net.workload.mono.toolchain.current\9.0.0-preview.2.24112.33\WorkloadManifest.json Install Type: Msi Host: Version: 9.0.0-preview.2.24112.33 Architecture: x64 Commit: 6299d3e88f .NET SDKs installed: 9.0.100-preview.2.24113.6 [C:\Program Files\dotnet\sdk] .NET runtimes installed: Microsoft.AspNetCore.App 9.0.0-preview.2.24112.25 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 9.0.0-preview.2.24112.33 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 9.0.0-preview.2.24112.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] ``` @dotnet-actwx-bot @dotnet/compat
Author: Junjun-zhao
Assignees: -
Labels: `area-Meta`, `untriaged`, `needs-author-action`
Milestone: -
Junjun-zhao commented 8 months ago

please follow-up with the maintainers of SharpScss. the stack above indicates native heap corruption within that component.

@jeffschwMSFT Thank you for checking this issue. Because this app works well on .NET 9 Preview 1 build but fail on Preview 2 build. Could you please help check what change cause this different behavior from Preview 2? Thanks.

Junjun-zhao commented 8 months ago

Closing this issue as it is an application issue and we've notified the owner of the application about this issue.