spatialaudio / jackclient-python

🂻 JACK Audio Connection Kit (JACK) Client for Python :snake:
https://jackclient-python.readthedocs.io/
MIT License
132 stars 26 forks source link

Using square brackets in get_ports() results in a segmentation fault. #63

Open MaurizioB opened 5 years ago

MaurizioB commented 5 years ago

With this code, python just crashes:

import jack
client = jack.Client('test')
print(client.get_ports('[]'))

I also tried different combinations (single bracket, adding text before, etc). The segfault happens on both Python 2.7.12 and 3.4.5.

mgeier commented 5 years ago

Thanks for the report!

This seems to be a bug in JACK which was reported to the mailing list in February: http://lists.jackaudio.org/pipermail/jack-devel-jackaudio.org/2019-February/001694.html (link may be for list members only?).

Anyway, this was transferred to a Github issue (https://github.com/jackaudio/jack2/issues/433) and the bug was promptly fixed (https://github.com/jackaudio/jack2/commit/d4ef6800b4fe9ee61d0b9a1b76af1292023a40e7).

There has been no new JACK2 release since then, so you'll have to compile it yourself to get the fixed version.

The same issue is not yet fixed in JACK1: https://github.com/jackaudio/jack1/issues/85

MaurizioB commented 5 years ago

Ok, if I understand it correctly, the fix just checks if the regex pattern is valid, right? For the time being (since I'm still using jack1), I think I'll override the get_ports method like this:

import re
import jack

def _get_ports_fix(self, name_pattern='', is_audio=False, is_midi=False,
                   is_input=False, is_output=False, is_physical=False,
                   can_monitor=False, is_terminal=False):
    if name_pattern:
        try:
            re.compile(name_pattern)
        except:
            return []
    return jack.Client._get_ports(self, name_pattern, is_audio, is_midi, 
                                  is_input, is_output, is_physical, 
                                  can_monitor, is_terminal)

jack.Client._get_ports = jack.Client.get_ports
jack.Client.get_ports = _get_ports_fix

Thank you for your answer. Let me know If you have a better solution.

mgeier commented 5 years ago

@MaurizioB Yes, I think in the meantime this is a reasonable work-around.

There might be some edge cases though, because I assume the two regex engines may have slightly different rules.

EternityForest commented 5 years ago

Not sure if this is helpful, but I have a trace of (what I think is) this thanks to faulthandler

Current thread 0x00007f7b04ff9700 (most recent call first): File "/usr/lib/python3/dist-packages/jack.py", line 315 in owns File "/usr/lib/python3/dist-packages/jack.py", line 1377 in _wrap_port_ptr File "/usr/lib/python3/dist-packages/jack.py", line 1265 in get_port_by_name File "/usr/lib/python3/dist-packages/jack.py", line 1361 in _port_list_from_pointers File "/usr/lib/python3/dist-packages/jack.py", line 1329 in get_ports File "Event_Carnyx_WebUI Backend", line 4 in _event_action File "/home/daniel/Projects/KaithemAutomation/kaithem/src/newevt.py", line 590 in _do_action File "/home/daniel/Projects/KaithemAutomation/kaithem/src/newevt.py", line 440 in _on_trigger File "/home/daniel/Projects/KaithemAutomation/kaithem/src/newevt.py", line 861 in _check File "/home/daniel/Projects/KaithemAutomation/kaithem/src/newevt.py", line 547 in check File "/home/daniel/Projects/KaithemAutomation/kaithem/src/newevt.py", line 195 in _run File "/home/daniel/Projects/KaithemAutomation/kaithem/src/workers.py", line 92 in workerloop File "/usr/lib/python3.6/threading.py", line 864 in run File "/usr/lib/python3.6/threading.py", line 916 in _bootstrap_inner File "/usr/lib/python3.6/threading.py", line 884 in _bootstrap

Version is 0.4.4