oleg-st / ZstdSharp

Port of zstd compression library to c#
MIT License
200 stars 29 forks source link

stackoverflow error in mono-6.12 when compressing data #26

Closed itn3000 closed 9 months ago

itn3000 commented 9 months ago

Overview

I tried to compress data with ZStdSharp.Compressor, stackoverflow error was occurred and terminated.

Steps to reproduce

  1. create new console app project
  2. add ZstdSharp.Port-0.7.2 nuget package and set TargetFramework to net48
  3. replace Program.cs code to gist code
  4. publish app to zstdtest
  5. build container image by Dockerfile in above url
  6. run container

Expected

output compressed data as Base64 and exit normaly

Actual

stackoverflow error occurred and exited abnomarly with following message

Stack overflow in unmanaged: IP: 0x55db998be9d3, fault addr: 0x7ffc88ab6ff8
Stack overflow: IP: 0x55db998be9d3, fault addr: 0x7ffc88aaeff8
Stacktrace:
  at <unknown> <0xffffffff>
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) [0x0002a] in <d45cca6b08764dd1be1588f2f544a081>:0
  <...>

Addtional

This code was worked as expected in net7.0 and net48+windows. But mono on windows(6.12.0.199), error was reproduced.

oleg-st commented 9 months ago

Is this reproduced in mono under windows ?

oleg-st commented 9 months ago

Mono doesn't seem to work well with function pointers

reported bug to mono https://github.com/mono/mono/issues/21716

oleg-st commented 9 months ago

I will make a workaround for this

oleg-st commented 9 months ago

Workaround is ready, will release a new version in a while.

jp-pino commented 9 months ago

I'm getting a segmentation fault when running a Xamarin.iOS application. Could it also be due to this?


Incident Identifier: 27FC449C-DB00-44B8-A35A-AAF595CCE3DC
CrashReporter Key:   A9B69D51-D451-5EEF-A444-F1F42FC9C697
Hardware Model:      MacBookPro18,3
Process:             TestApp.iOS [5157]
Path:                /Users/USER/Library/Developer/CoreSimulator/Devices/306E2CB5-A850-433B-B3C9-1F7EF85D6E34/data/Containers/Bundle/Application/D9F26AA6-98F1-49A2-9735-16CBBCC2BAC4/TestApp.iOS.app/TestApp.iOS
Identifier:          com.companyname.TestApp
Version:             1.0 (1.0)
Code Type:           X86-64 (Native)
Role:                Foreground
Parent Process:      launchd_sim [423]
Coalition:           com.apple.CoreSimulator.SimDevice.306E2CB5-A850-433B-B3C9-1F7EF85D6E34 [60188]
Responsible Process: SimulatorTrampoline [2367]

Date/Time:           2023-10-18 11:50:09.7025 +0200
Launch Time:         2023-10-18 11:50:01.2506 +0200
OS Version:          macOS 14.0 (23A344)
Release Type:        User
Report Version:      104

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_PROTECTION_FAILURE at 0x000000030dde9ff8
Exception Codes: 0x0000000000000002, 0x000000030dde9ff8
VM Region Info: 0x30dde9ff8 is in 0x30a5e6000-0x30ddea000;  bytes after start: 58736632  bytes before end: 7
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      unused __TEXT               2059b9000-2059bb000    [    8K] r--/r-- SM=NUL  ...ed lib __TEXT
      GAP OF 0x104c2b000 BYTES
--->  Stack Guard                 30a5e6000-30ddea000    [ 56.0M] ---/rwx SM=NUL  
      Stack                       30ddea000-30e5e6000    [ 8176K] rw-/rwx SM=SHM  
Termination Reason: SIGNAL 11 Segmentation fault: 11
Terminating Process: exc handler [5157]

Triggered by Thread:  0

Kernel Triage:
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter

Thread 0 Crashed:: tid_103 Dispatch queue: com.apple.main-thread
0   <translation info unavailable>         0x105d27658 ???
1   TestApp.iOS                            0x104e38975 mono_class_get_flags + 69
2   TestApp.iOS                            0x104e38975 mono_class_get_flags + 69
3   TestApp.iOS                            0x104e38975 mono_class_get_flags + 69
...
oleg-st commented 9 months ago

@jp-pino If it uses mono of the same version, then yes

oleg-st commented 9 months ago

@itn3000 @jp-pino

0.7.3 has been released

jp-pino commented 9 months ago

Thank you! I think everything is working correctly. Will let you know if any problems arise :)