Project

General

Profile

Actions

Bug #1439

open
CB

babeltrace Python bindings segfault on Python 3.14 when reading trace

Bug #1439: babeltrace Python bindings segfault on Python 3.14 when reading trace

Added by Christophe Bedard about 1 month ago. Updated about 1 month ago.

Status:
In Progress
Priority:
Normal
Assignee:
-
Category:
-
Start date:
04/30/2026
Due date:
% Done:

0%

Estimated time:

Description

Files to reproduce

  1. Create `/tmp/babeltrace1.5-python`
  2. Unzip `trace.tar.xz` into `/tmp/babeltrace1.5-python/trace/`
  3. Create the following Python script `/tmp/babeltrace1.5-python/trace/repro_minimal.py`:

""" 
Minimal reproducer.

Opens an existing CTF/LTTng trace with babeltrace1's Python bindings and
iterates field names per event. On Python 3.14 / Ubuntu 26.04, this segfaults
inside `_bt_python_field_one_from_list` because the C wrapper returns a NULL
list pointer with an uninitialized count.

Reader is assumed to have the trace at the path below.
""" 
import sys
import faulthandler
faulthandler.enable()

import babeltrace

TRACE_DIR = '/tmp/babeltrace1.5-python/trace'

print(f'Python: {sys.version.splitlines()[0]}')
print(f'babeltrace: {babeltrace.__version__}')
print(f'Trace dir: {TRACE_DIR}')

tc = babeltrace.TraceCollection()
tc.add_traces_recursive(TRACE_DIR, 'ctf')

for event in tc.events:
    print(f'event {event.name!r} ts={event.timestamp}')
    print('  about to call event.keys() ...', flush=True)
    keys = event.keys()  # <-- crashes here on Python 3.14
    print(f'  keys = {keys}')
print('DONE')

Steps reproduce on Python 3.14 and Ubuntu 26.04

$ docker run --rm -it -v /tmp/babeltrace1.5-python:/tmp/babeltrace1.5-python ubuntu:26.04 bash -c '
  apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq python3-babeltrace && python3 --version && python3 /tmp/babeltrace1.5-python/repro_minimal.py
'

Actual output output with Python 3.14 (Ubuntu 26.04): segfault

Python 3.14.4
Python: 3.14.4 (main, Apr  8 2026, 04:02:31) [GCC 15.2.0]
babeltrace: 1.5.11
Trace dir: /tmp/babeltrace1.5-python/trace
event 'lttng_ust_tracef:event' ts=1777503018164567458
  about to call event.keys() ...
Fatal Python error: Segmentation fault

Current thread 0x000072cf0dcc51c0 [python3] (most recent call first):
  File "/usr/lib/python3/dist-packages/babeltrace/babeltrace.py", line 83 in _bt_python_field_one_from_list
  File "/usr/lib/python3/dist-packages/babeltrace/babeltrace.py", line 839 in _field_list_with_scope
  File "/usr/lib/python3/dist-packages/babeltrace/babeltrace.py", line 719 in field_list_with_scope
  File "/usr/lib/python3/dist-packages/babeltrace/babeltrace.py", line 792 in keys
  File "/tmp/babeltrace1.5-python/repro_minimal.py", line 29 in <module>

Current thread's C stack trace (most recent call first):
  Binary file "python3", at _Py_DumpStack+0x4a [0x476e25]
  Binary file "python3" [0x504188]
  Binary file "/usr/lib/x86_64-linux-gnu/libc.so.6", at +0x45cb0 [0x72cf0dd0bcb0]
  Binary file "/usr/lib/python3/dist-packages/babeltrace/_babeltrace.cpython-314-x86_64-linux-gnu.so", at _bt_python_field_one_from_list+0x7 [0x72cf0d9bc627]
  Binary file "/usr/lib/python3/dist-packages/babeltrace/_babeltrace.cpython-314-x86_64-linux-gnu.so", at +0x156b5 [0x72cf0d9bc6b5]
  Binary file "python3" [0x5772b9]
  Binary file "python3", at _PyObject_MakeTpCall+0x36c [0x52f3fc]
  Binary file "python3", at _PyEval_EvalFrameDefault+0xe66 [0x54d936]
  Binary file "python3", at PyEval_EvalCode+0x106 [0x547bd6]
  Binary file "python3" [0x6cb701]
  Binary file "python3" [0x6c82b1]
  Binary file "python3" [0x6c795b]
  Binary file "python3" [0x6c7429]
  Binary file "python3", at Py_RunMain+0x349 [0x6c50e9]
  Binary file "python3", at Py_BytesMain+0x34 [0x6744b4]
  Binary file "/usr/lib/x86_64-linux-gnu/libc.so.6", at +0x2a601 [0x72cf0dcf0601]
  Binary file "/usr/lib/x86_64-linux-gnu/libc.so.6", at __libc_start_main+0x88 [0x72cf0dcf0718]
  Binary file "python3", at _start+0x25 [0x6738b5]

Extension modules: babeltrace._babeltrace (total: 1)

Expected output == actual output on Python 3.12 (Ubuntu 24.04): works

Just change the Docker image to `ubundu:24.04`:

Python 3.12.3
Python: 3.12.3 (main, Mar 23 2026, 19:04:32) [GCC 13.3.0]
babeltrace: 1.5.11
Trace dir: /tmp/babeltrace1.5-python/trace
event 'lttng_ust_tracef:event' ts=1777503018164567458
  about to call event.keys() ...
  keys = ['cpu_id', 'content_size', 'id', 'v', 'procname', 'vtid', 'packet_seq_num', 'uuid', 'timestamp_end', 'events_discarded', 'stream_instance_id', 'timestamp_begin', 'magic', 'stream_id', '_msg_length', 'vpid', 'msg', 'packet_size']
event 'lttng_ust_tracef:event' ts=1777503018178240108
  about to call event.keys() ...
  keys = ['cpu_id', 'content_size', 'id', 'v', 'procname', 'vtid', 'packet_seq_num', 'uuid', 'timestamp_end', 'events_discarded', 'stream_instance_id', 'timestamp_begin', 'magic', 'stream_id', '_msg_length', 'vpid', 'msg', 'packet_size']
event 'ros2:rmw_publisher_init' ts=1777503018183106175
...
DONE

Files

trace.tar.xz (3.67 KB) trace.tar.xz test trace Christophe Bedard, 04/30/2026 12:43 PM

KS Updated by Kienan Stewart about 1 month ago Actions #1

Hi Christophe,

thanks for the bug report. Babeltrace 1.5 is no longer supported. Are you able to use Babeltrace 2.1 or Babeltrace 2.0?

thanks,
kienan

SM Updated by Simon Marchi about 1 month ago · Edited Actions #2

Kienan Stewart wrote in #note-1:

Hi Christophe,

thanks for the bug report. Babeltrace 1.5 is no longer supported. Are you able to use Babeltrace 2.1 or Babeltrace 2.0?

thanks,
kienan

Yes he knows, see comment here (copied below):

https://review.lttng.org/c/babeltrace/+/17654/3#message-d2e532ec90822978f09c465d5c84ef088a01e6ea

I know that babeltrace1 is pretty old at this point, but I hit this as part of a move to Ubuntu 26.04, so I assume I won't be the only one.

I do plan to move to babeltrace2 (and bt2)!

CB Updated by Christophe Bedard about 1 month ago Actions #3

For what it's worth, I worked around it in my code (for now) by just rewriting a `babeltrace` function:

import babeltrace.babeltrace as _bt_impl

def _safe_field_list_with_scope(self, scope: int) -> list:
    fields: list = []
    scope_ptr = _bt_impl._bt_ctf_get_top_level_scope(self._e, scope)
    if scope_ptr is None:
        return fields  # avoid the buggy C error path entirely
    ret = _bt_impl._bt_python_field_listcaller(self._e, scope_ptr)
    if not isinstance(ret, list):
        return fields
    list_ptr, count = ret
    if list_ptr is None:
        return fields
    for i in range(count):
        definition_ptr = _bt_impl._bt_python_field_one_from_list(list_ptr, i)
        if definition_ptr is not None:
            fields.append(_bt_impl._Definition(definition_ptr, scope))
    return fields

_bt_impl.Event._field_list_with_scope = _safe_field_list_with_scope

I'll most likely work on upgrading to `bt2` from here.

CB Updated by Christophe Bedard about 1 month ago Actions #4

The fix has been merged: https://review.lttng.org/c/babeltrace/+/17654

I'll personally work on switching to bt2, but I don't know if it's possible to get a new 1.5 release into Ubuntu 26.04 or wherever the Python bindings are built with SWIG >=4.3.0.

JG Updated by Jérémie Galarneau about 1 month ago Actions #5

  • Status changed from New to In Progress

There won't be anoter release of 1.5 since it's been EOL'ed a while ago.

@Michael Jeanson Can weigh-in on this, but I think the most realistic way forward is to distro-patch the package. AFAIK, that requires someone to open a bug against the Ubuntu package. Then the package maintainer can decide to add the patch or not.

@christophebedard would you be open to opening that bug?

MJ Updated by Michael Jeanson about 1 month ago Actions #6

Jérémie Galarneau wrote in #note-5:

@Michael Jeanson Can weigh-in on this, but I think the most realistic way forward is to distro-patch the package. AFAIK, that requires someone to open a bug against the Ubuntu package. Then the package maintainer can decide to add the patch or not.

Assuming there is a patch available, you can open a bug in launchpad against the babeltrace package and convince someone from Ubuntu to create an SRU.

CB Updated by Christophe Bedard about 1 month ago Actions #7

There won't be anoter release of 1.5 since it's been EOL'ed a while ago.

Totally fair.

@Christophe Bedard would you be open to opening that bug?

Absolutely, here it is: https://bugs.launchpad.net/ubuntu/+source/babeltrace/+bug/2152060.

Actions

Also available in: PDF Atom