KxSystems / embedPy

Allows the kdb+ interpreter to call Python functions
https://code.kx.com/q/interfaces
Apache License 2.0
89 stars 42 forks source link

Segfault when passing corrupt unicode to a python function #18

Closed clovetea closed 6 years ago

clovetea commented 6 years ago
KDB+ 3.5 2017.08.22 Copyright (C) 1993-2017 Kx Systems
l64/ 16()core 122525MB ben labs1.firstderivatives.com 10.139.127.17 EXPIRE 2018.03.16 firstderivatives.com INTERNAL #49564

q)\l p.q
q)p)def string_length(x): return len(x)
q)stringLength: .p.callable .p.pyeval "string_length"
q)stringLength "Hello World"
11
q)stringLength "Hello\351World"
Sorry, this application or an associated library has encountered a fatal error and will exit.
If known, please email the steps to reproduce this error to tech@kx.com
with a copy of the kdb+ startup banner.
Thank you.
q() [0x473a11]
/usr/lib64/libpthread.so.0(+0xf100) [0x7f3fcee38100]
/usr/local/lib/libpython3.5m.so.1.0(+0x15c0a1) [0x7f3fc81460a1]
/usr/local/lib/libpython3.5m.so.1.0(PyEval_EvalCodeEx+0x48) [0x7f3fc81469d8]
/usr/local/lib/libpython3.5m.so.1.0(+0x9e723) [0x7f3fc8088723]
/usr/local/lib/libpython3.5m.so.1.0(PyObject_Call+0x6a) [0x7f3fc8057a2a]
/IVY/instances/1264/delta-bin/software/KDBPlus_3_5_0/l64/./p.so(+0x2bd0) [0x7f3fc850fbd0]
q() [0x472c59]
q() [0x43c2e6]
q() [0x43c2c5]
q() [0x43e55a]
q() [0x43c13e]
q() [0x43c2c5]
q() [0x43c715]
q() [0x41d350]
rlwrap: warning: q crashed, killed by SIGSEGV (core dumped).
rlwrap itself has not crashed, but for transparency,
it will now kill itself with the same signal

warnings can be silenced by the --no-warnings (-n) option
Segmentation fault (core dumped)
jhanna-kx commented 6 years ago

Thanks, we'll look at a fix for this as soon as possible

effbiae commented 6 years ago

see commit #21 try .p.q2py"Hello\351World"

jhanna-kx commented 6 years ago

23 should fix this for .p.eval and .p.pyeval in the mean time until .p.q2py is applied on things passed to these functions

jfakx commented 6 years ago

so shall we change runs to accept last arg as foreign? eval:{runs[1;q2py x]}

jfakx commented 6 years ago

or leave runs as it is and runs[1;py2q q2py x] to handle bad encodings

jhanna-kx commented 6 years ago

I think runs accepting a foreign would be fine, and q2py then throwing the python unicode error if everything goes through q2py