bloomberg / memray

Memray is a memory profiler for Python
https://bloomberg.github.io/memray/
Apache License 2.0
13.36k stars 397 forks source link

`memray attach` with lldb can trigger an abort due to stack smashing detection #471

Open godlygeek opened 1 year ago

godlygeek commented 1 year ago

I'm not 100% sure yet what's causing this, and so far I've only been able to reproduce it with lldb, not gdb. But this tiny one-line change to our test suite:

diff --git a/tests/integration/test_attach.py b/tests/integration/test_attach.py
index f321087..52876ca 100644
--- a/tests/integration/test_attach.py
+++ b/tests/integration/test_attach.py
@@ -91,6 +91,7 @@ def run_process(cmd):
     # WHEN
     try:
         subprocess.check_output(cmd, stderr=subprocess.STDOUT, text=True)
+        subprocess.check_output(cmd, stderr=subprocess.STDOUT, text=True)
     except subprocess.CalledProcessError as exc:
         if "Couldn't write extended state status" in exc.output:
             # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=898048

Is enough to fairly reliably provoke this failure:

tests/integration/test_attach.py::test_basic_attach[lldb] *** stack smashing detected ***: /home/mwoznisk/.pyenv/versions/memray-3.11/bin/python terminated
======= Backtrace: =========
/lib64/libc.so.6(__fortify_fail+0x37)[0x7f51f340c7a7]
/lib64/libc.so.6(+0x118762)[0x7f51f340c762]
/home/mwoznisk/repos/memray-pr/src/memray/_memray.cpython-311-x86_64-linux-gnu.so(+0x84eeb)[0x7f51f2e61eeb]
/home/mwoznisk/repos/memray-pr/src/memray/_test_utils.cpython-311-x86_64-linux-gnu.so(+0x149e0)[0x7f51f2a689e0]
...