ironpython3
ironpython3 copied to clipboard
Incorrect usage of ctype causes ironpython crashing.
The incorrect usage of ctype causes core dumped. See the following example. The crash report indicates that the memory seems to leak.
Environmental:
IronPython 3.4.0a1 (3.4.0.0001)
[.NETFramework,Version=v4.6 on Mono 6.12.0.122 (tarball Mon Feb 22 17:28:32 UTC 2021) (64-bit)] on linux
test.py
from __future__ import print_function
import ctypes
import ctypes.util
lib_location = ctypes.util.find_library('gettextpo')
gpo = ctypes.cdll.LoadLibrary(lib_location)
gpo_message = gpo.po_message_create()
source = 'foo'
print('calling po_message_set_msgid')
gpo.po_message_set_msgid(source, source.encode('utf-8'))
print('success')
Crash report:
(base) xxm@xxm-System-Product-Name:~$ ipy test.py
calling po_message_set_msgid
=================================================================
Native Crash Reporting
=================================================================
Got a SIGSEGV 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:
=================================================================
0x4b8999 - /usr/bin/mono :
0x4b8d09 - /usr/bin/mono :
0x4626df - /usr/bin/mono :
0x4b17e6 - /usr/bin/mono :
0x7fb394d61562 - /lib/x86_64-linux-gnu/libc.so.6 : cfree
0x40368238 - Unknown
=================================================================
Telemetry Dumper:
=================================================================
Could not exec mono-hang-watchdog, expected on path '/etc/../bin/mono-hang-watchdog' (errno 2)
Pkilling 0x140409121285888x from 0x140409296553856x
Pkilling 0x140409223927552x from 0x140409296553856x
Pkilling 0x140409112880896x from 0x140409296553856x
Pkilling 0x140409117083392x from 0x140409296553856x
Pkilling 0x140409108678400x from 0x140409296553856x
Pkilling 0x140409084278528x from 0x140409296553856x
Pkilling 0x140409080076032x from 0x140409296553856x
Pkilling 0x140409097418496x from 0x140409296553856x
Pkilling 0x140409093216000x from 0x140409296553856x
Pkilling 0x140409089013504x from 0x140409296553856x
Pkilling 0x140409123387136x from 0x140409296553856x
Pkilling 0x140409119184640x from 0x140409296553856x
Pkilling 0x140409114982144x from 0x140409296553856x
Pkilling 0x140409110779648x from 0x140409296553856x
Pkilling 0x140409082177280x from 0x140409296553856x
Pkilling 0x140409077974784x from 0x140409296553856x
Pkilling 0x140409095317248x from 0x140409296553856x
Pkilling 0x140409091114752x from 0x140409296553856x
Pkilling 0x140409086912256x from 0x140409296553856x
Entering thread summarizer pause from 0x140409296553856x
Finished thread summarizer pause from 0x140409296553856x.
Failed to create breadcrumb file (null)/crash_hash_0xb66d8c8b3
Waiting for dumping threads to resume
=================================================================
External Debugger Dump:
=================================================================
[New LWP 22222]
[New LWP 22223]
[New LWP 22248]
[New LWP 22249]
[New LWP 22250]
[New LWP 22252]
[New LWP 22253]
[New LWP 22254]
[New LWP 22256]
[New LWP 22257]
[New LWP 22320]
[New LWP 22321]
[New LWP 22326]
[New LWP 22328]
[New LWP 22329]
[New LWP 22330]
[New LWP 22335]
[New LWP 22338]
[New LWP 22339]
[New LWP 22341]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
0x00007fb3959bbf7b in __waitpid (pid=22532, stat_loc=0x7ffd5a6f8f74, options=0) at ../sysdeps/unix/sysv/linux/waitpid.c:29
29 ../sysdeps/unix/sysv/linux/waitpid.c: No such file or directory.
Id Target Id Frame
.................
#62 0x00007ffd5a6fa0b0 in ?? ()
#63 0xcff4ad40cc528b00 in ?? ()
#64 0x00007fb388a6b5b0 in ?? ()
#65 0x0000000002465ca8 in ?? ()
#66 0x00007fb394787860 in ?? ()
#67 0x00007fb3947c1830 in ?? ()
#68 0x00007fb394782dc0 in ?? ()
#69 0x0000000000000000 in ?? ()
=================================================================
Basic Fault Address Reporting
=================================================================
Memory around native instruction pointer (0x7fb394d61562):0x7fb394d61552 8b 00 48 85 c0 0f 85 d3 00 00 00 48 85 ff 74 2a ..H........H..t*
0x7fb394d61562 48 8b 47 f8 48 8d 77 f0 a8 02 75 32 a8 04 48 8d H.G.H.w...u2..H.
0x7fb394d61572 3d a9 05 34 00 74 0c 48 89 f0 48 25 00 00 00 fc =..4.t.H..H%....
0x7fb394d61582 48 8b 38 31 d2 e8 d4 b7 ff ff 48 83 c4 28 5b 5d H.81......H..([]
=================================================================
Managed Stacktrace:
=================================================================
at <unknown> <0xffffffff>
at System.Object:wrapper_native_0x7fb343bb2210 <0x00087>
at System.Object:InteropInvoker <0x000cc>
at System.Object:CallSite.Target <0x00272>
at System.Dynamic.UpdateDelegates:UpdateAndExecute3 <0x006bd>
at Microsoft.Scripting.Interpreter.DynamicInstruction`4:Run <0x00174>
at Microsoft.Scripting.Interpreter.Interpreter:Run <0x0013e>
at Microsoft.Scripting.Interpreter.LightLambda:Run5 <0x0018f>
at System.Dynamic.UpdateDelegates:UpdateAndExecute4 <0x006ec>
at System.Func`6:invoke_TResult_T1_T2_T3_T4_T5 <0x000dc>
at System.Object:CallSite.Target <0x001a6>
at Invoke2Instruction:Run <0x000c1>
at Microsoft.Scripting.Interpreter.Interpreter:Run <0x0013e>
at Microsoft.Scripting.Interpreter.LightLambda:Run1 <0x000eb>
at IronPython.Compiler.RuntimeScriptCode:InvokeTarget <0x00179>
at IronPython.Compiler.RuntimeScriptCode:Run <0x0002f>
at IronPython.Hosting.PythonCommandLine:RunFileWorker <0x003ea>
at IronPython.Hosting.PythonCommandLine:RunFile <0x0008f>
at Microsoft.Scripting.Hosting.Shell.CommandLine:Run <0x00085>
at IronPython.Hosting.PythonCommandLine:Run <0x003fb>
at Microsoft.Scripting.Hosting.Shell.CommandLine:Run <0x0010a>
at Microsoft.Scripting.Hosting.Shell.ConsoleHost:RunCommandLine <0x00177>
at Microsoft.Scripting.Hosting.Shell.ConsoleHost:ExecuteInternal <0x000bb>
at PythonConsoleHost:ExecuteInternal <0x00073>
at Microsoft.Scripting.Hosting.Shell.ConsoleHost:Execute <0x00140>
at Microsoft.Scripting.Hosting.Shell.ConsoleHost:Run <0x0068f>
at PythonConsoleHost:Main <0x00082>
at <Module>:runtime_invoke_int_object <0x00085>
=================================================================
Aborted (core dumped)
Unfortunately I haven't been able to reproduce. I guess it's because I don't have gettextpo
in my linux distro?
I do have gettextpo
and the above code crashes with CPython (3.8.10) too. (Interestingly, it does not crash with IronPython on .NET Core, only on Mono, but this could be a random fluke). I think this is not a bug in CPython or IronPython but simply a bug in the user code. ctypes
, if used incorrectly, can corrupt the memory and crash the process as a result, in random ways. This is by design. It gives the user the power but also the responsibility of programming in an unmanaged language, like C.