pybind / pybind/pybind11

[BUG]: Many pybind11 tests fail under ASan/UBSan

Open
#3,655 2 comments 0 reactions 1 assignee View on GitHub

@rwgk is already working on this.

Since Jan 27, 2022.

triage
Dominant language
C++
Stars
18k
Forks
2.3k
Avg merge
5d 17h
Merged PRs (30d)
10

Description

Required prerequisites
Problem description

In user code I have been observing lots of segfaults and UB; naturally I tried to discover its cause via ASan and UBSan. After discovering issue #3514 it was unclear to me where the fixes should go: In user code or in pybind11. Hence I ran the pybind11 unit tests after a compilation with:

cmake -DDOWNLOAD_CATCH=ON  -DCMAKE_CXX_FLAGS="-fsanitize=address -fsanitize=undefined -g" ../ -G Ninja

The following tests failed:

~/pybind11/build/tests ❯❯❯ python3 -m pytest ../../tests/ -v
../../tests/test_builtin_casters.py::test_single_char_arguments 
~/pybind11/include/pybind11/detail/internals.h:391:46: runtime error: member call on address 0x000130eb9540 which does not point to an object of type 'pybind11::builtin_exception'
0x000130eb9540: note: object is of type 'pybind11::value_error'
 01 00 00 00  88 75 9e 17 01 00 00 00  28 78 16 3a 01 00 00 00  dd dd dd dd dd dd dd dd  00 00 00 00
              ^~~~~~~~~~~~~~~~~~~~~~~
              vptr for 'pybind11::value_error'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior 
~/pybind11/include/pybind11/detail/internals.h:391:46 in
PASSED                                                                                 [  2%]
../../tests/test_local_bindings.py::test_stl_bind_local 
~/pybind11/include/pybind11/detail/internals.h:391:46: runtime error: member call on address 0x0001134b83c0 which does not point to an object of type 'pybind11::builtin_exception'
0x0001134b83c0: note: object is of type 'pybind11::stop_iteration'
 01 00 00 00  c8 ca 9f 17 01 00 00 00  18 e4 37 0a 01 00 00 00  dd dd dd dd dd dd dd dd  00 00 00 00
              ^~~~~~~~~~~~~~~~~~~~~~~
              vptr for 'pybind11::stop_iteration'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior 
~/pybind11/include/pybind11/detail/internals.h:391:46 in
PASSED                                                                                         [ 51%]
../../tests/test_numpy_dtypes.py::test_recarray ~/pybind11/tests/test_numpy_dtypes.cpp:56:30: runtime error: reference binding to misaligned address 0x000147c4fc29 for type 'const SimpleStruct', which requires 8 byte alignment
0x000147c4fc29: note: pointer points here
 00 00 04  c0 01 be be be 01 00 00  00 00 00 c0 3f be be be  be 00 00 00 00 00 00 04  c0 00 02 00 00
              ^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior 
~/pybind11/tests/test_numpy_dtypes.cpp:56:30 in
FAILED                                                                                                 [ 71%]

Note that the python interpreter must be source compiled with ./configure --with-address-sanitizer --with-pydebug.

Reproducible example code
In the repo.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.