Skip to content

[BUG]: bounds checking problem #5224

Open
@0-wiz-0

Description

@0-wiz-0

Required prerequisites

What version (or hash if on master) of pybind11 are you using?

2.13.1

Problem description

When compiling contourpy with bounds checking (-fstack-clash-protection) enabled, I get a compilation error (because contourpy by default builds with -Werror). That's with gcc 12.4.0 on NetBSD-10.99.11/amd64.

I reported this to the contourpy project but they said it's a problem in pybind11.

Here's the compilation output:

[12/14] c++ -Isrc/_contourpy.so.p -Isrc -I../src -I/usr/pkg/include/python3.12 -I/usr/pkg/lib/python3.12/site-packages/pybind11/include -I/usr/pkg/include -I/usr/include -fvisibility=hidden -fdiagnostics-color=always -DNDEBUG -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=c++17 -O3 -O2 -g -fstack-clash-protection -g -fPIC -DCONTOURPY_VERSION=1.2.1 -MD -MQ src/_contourpy.so.p/wra
p.cpp.o -MF src/_contourpy.so.p/wrap.cpp.o.d -o src/_contourpy.so.p/wrap.cpp.o -c ../src/wrap.cpp
FAILED: src/_contourpy.so.p/wrap.cpp.o
c++ -Isrc/_contourpy.so.p -Isrc -I../src -I/usr/pkg/include/python3.12 -I/usr/pkg/lib/python3.12/site-packages/pybind11/include -I/usr/pkg/include -I/usr/include -fvisibility=hidden -fdiagnostics-color=always -DNDEBUG -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=c++17 -O3 -O2 -g -fstack-clash-protection -g -fPIC -DCONTOURPY_VERSION=1.2.1 -MD -MQ src/_contourpy.so.p/wrap.cpp.o
In file included from /usr/include/g++/bits/forward_list.h:38,
                 from /usr/include/g++/forward_list:38,
                 from /scratch/graphics/py-contourpy/work/.buildlink/lib/python3.12/site-packages/pybind11/include/pybind11/detail/../detail/common.h:317,
                 from /scratch/graphics/py-contourpy/work/.buildlink/lib/python3.12/site-packages/pybind11/include/pybind11/detail/../attr.h:13,
                 from /scratch/graphics/py-contourpy/work/.buildlink/lib/python3.12/site-packages/pybind11/include/pybind11/detail/class.h:12,
                 from /scratch/graphics/py-contourpy/work/.buildlink/lib/python3.12/site-packages/pybind11/include/pybind11/pybind11.h:13,
                 from ../src/common.h:4,
                 from ../src/output_array.h:4,
                 from ../src/chunk_local.h:4,
                 from ../src/base.h:13,
                 from ../src/base_impl.h:4,
                 from ../src/wrap.cpp:1:
In static member function 'static _Up* std::__copy_move<_IsMove, true, std::random_access_iterator_tag>::__copy_m(_Tp*, _Tp*, _Up*) [with _Tp = pybind11::detail::type_info* const; _Up = pybind11::detail::type_info*; bool _IsMove = false]',
    inlined from '_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = false; _II = pybind11::detail::type_info* const*; _OI = pybind11::detail::type_info**]' at /usr/include/g++/bits/stl_algobase.h:501:30,
    inlined from '_OI std::__copy_move_a1(_II, _II, _OI) [with bool _IsMove = false; _II = pybind11::detail::type_info* const*; _OI = pybind11::detail::type_info**]' at /usr/include/g++/bits/stl_algobase.h:528:42,
    inlined from '_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = false; _II = pybind11::detail::type_info* const*; _OI = pybind11::detail::type_info**]' at /usr/include/g++/bits/stl_algobase.h:535:31,
    inlined from '_OI std::copy(_II, _II, _OI) [with _II = pybind11::detail::type_info* const*; _OI = pybind11::detail::type_info**]' at /usr/include/g++/bits/stl_algobase.h:626:7,
    inlined from 'static _ForwardIterator std::__uninitialized_copy<true>::__uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = pybind11::detail::type_info* const*; _ForwardIterator = pybind11::detail::type_info**]' at /usr/include/g++/bits/stl_uninitialized.h:147:27,
    inlined from '_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = pybind11::detail::type_info* const*; _ForwardIterator = pybind11::detail::type_info**]' at /usr/include/g++/bits/stl_uninitialized.h:185:15,
    inlined from '_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, allocator<_Tp>&) [with _InputIterator = pybind11::detail::type_info* const*; _ForwardIterator = pybind11::detail::type_info**; _Tp = pybind11::detail::type_info*]' at /usr/include/g++/bits/stl_uninitialized.h:372:37,
    inlined from 'void std::vector<_Tp, _Alloc>::_M_assign_aux(_ForwardIterator, _ForwardIterator, std::forward_iterator_tag) [with _ForwardIterator = pybind11::detail::type_info* const*; _Tp = pybind11::detail::type_info*; _Alloc = std::allocator<pybind11::detail::type_info*>]' at /usr/include/g++/bits/vector.tcc:339:35,
    inlined from 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = pybind11::detail::type_info*; _Alloc = std::allocator<pybind11::detail::type_info*>]' at /usr/include/g++/bits/stl_vector.h:787:21,
    inlined from 'pybind11::detail::generic_type::initialize(const pybind11::detail::type_record&)::<lambda(pybind11::detail::internals&)>' at /scratch/graphics/py-contourpy/work/.buildlink/lib/python3.12/site-packages/pybind11/include/pybind11/pybind11.h:1434:75,
    inlined from 'decltype (cb(pybind11::detail::get_internals())) pybind11::detail::with_internals(const F&) [with F = generic_type::initialize(const pybind11::detail::type_record&)::<lambda(internals&)>]' at /scratch/graphics/py-contourpy/work/.buildlink/lib/python3.12/site-packages/pybind11/include/pybind11/detail/../detail/internals.h:626:14,
    inlined from 'void pybind11::detail::generic_type::initialize(const pybind11::detail::type_record&)' at /scratch/graphics/py-contourpy/work/.buildlink/lib/python3.12/site-packages/pybind11/include/pybind11/pybind11.h:1426:23:
/usr/include/g++/bits/stl_algobase.h:434:30: error: 'void* __builtin_memcpy(void*, const void*, long unsigned int)' forming offset 8 is out of the bounds [0, 8] of object '<anonymous>' with type 'pybind11::detail::type_info* const [1]' [-Werror=array-bounds]
  434 |             __builtin_memmove(__result, __first, sizeof(_Tp) * _Num);
      |             ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/scratch/graphics/py-contourpy/work/.buildlink/lib/python3.12/site-packages/pybind11/include/pybind11/pybind11.h: In member function 'void pybind11::detail::generic_type::initialize(const pybind11::detail::type_record&)':
/scratch/graphics/py-contourpy/work/.buildlink/lib/python3.12/site-packages/pybind11/include/pybind11/pybind11.h:1434:75: note: '<anonymous>' declared here
 1434 |             internals.registered_types_py[(PyTypeObject *) m_ptr] = {tinfo};
      |                                                                           ^
cc1plus: all warnings being treated as errors
ninja: build stopped: subcommand failed.

I tried it also with pybind11 2.12.0, same problem there.

Reproducible example code

See above.

Is this a regression? Put the last known working version here if it is.

Not a regression

Metadata

Metadata

Assignees

No one assigned

    Labels

    triageNew bug, unverified

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions