Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AffineConstraints: out of bounds vector access #15427

Closed
tamiko opened this issue Jun 22, 2023 · 1 comment · Fixed by #15431
Closed

AffineConstraints: out of bounds vector access #15427

tamiko opened this issue Jun 22, 2023 · 1 comment · Fixed by #15431

Comments

@tamiko
Copy link
Member

tamiko commented Jun 22, 2023

My desktop system has a "hardened" libstdc++ library version installed that has assertions for bounds checks compiled in. When running the testsuite a number of tests are failing for me with an assert. For example:

/usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/stl_vector.h:1125: std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = unsigned int; _Alloc = std::allocator<unsigned int>; reference = unsigned int&; size_type = long unsigned int]: Assertion '__n < this->size()' failed.

Here is an exemplary stack trace how the assertion is triggered:

#0  __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
#1  0x00007fffb94afd63 in __pthread_kill_internal (signo=6, threadid=<optimized out>) at pthread_kill.c:78
#2  0x00007fffb9460f26 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#3  0x00007fffb944a87c in __GI_abort () at abort.c:79
#4  0x00007fffaeb0f78f in std::__glibcxx_assert_fail(char const*, int, char const*, char const*)
    (file=<optimized out>, line=<optimized out>, function=<optimized out>, condition=<optimized out>)
    at /var/tmp/portage/sys-devel/gcc-13.1.1_p20230527/work/gcc-13-20230527/libstdc++-v3/src/c++11/debug.cc:61
#5  0x0000555555868b79 in std::vector<unsigned int, std::allocator<unsigned int> >::operator[](unsigned long) (this=0x555555c86d60, __n=18446744073709551615)
    at /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/stl_vector.h:1125
#6  0x00007ffff294ad5b in dealii::AffineConstraints<double>::make_sorted_row_list(std::vector<unsigned int, std::allocator<unsigned int> > const&, std::vector<unsigned int, std::allocator<unsigned int> >&) const (this=0x555555c13338, local_dof_indices=std::vector of length 3, capacity 3 = {...}, active_dofs=std::vector of length 0, capacity 3)
    at /home/tamiko/workspace/dealii/include/deal.II/lac/affine_constraints.templates.h:3847
#7  0x00007ffff2948ba4 in dealii::AffineConstraints<double>::add_entries_local_to_global(std::vector<unsigned int, std::allocator<unsigned int> > const&, dealii::SparsityPatternBase&, bool, dealii::Table<2, bool> const&) const
    (this=0x555555c13338, local_dof_indices=std::vector of length 3, capacity 3 = {...}, sparsity_pattern=..., keep_constrained_entries=true, dof_mask=...)
    at /home/tamiko/workspace/dealii/include/deal.II/lac/affine_constraints.templates.h:4320
#8  0x00007ffff28f7766 in dealii::DoFTools::make_sparsity_pattern<2, 2, double>(dealii::DoFHandler<2, 2> const&, dealii::SparsityPatternBase&, dealii::AffineConstraints<double> const&, bool, unsigned int) (dof=..., sparsity=..., constraints=..., keep_constrained_dofs=true, subdomain_id=4294967295)
    at /home/tamiko/workspace/dealii/source/dofs/dof_tools_sparsity.cc:103
#9  0x0000555555881423 in Operator<2, double>::get_system_matrix() const (this=0x555555c12c50)
    at /home/tamiko/workspace/dealii/tests/multigrid-global-coarsening/multigrid_util.h:170
#10 0x0000555555856992 in mg_solve<dealii::LinearAlgebra::distributed::Vector<double, dealii::MemorySpace::Host>, 2, Operator<2, double>, Operator<2, double>, dealii::MGTransferGlobalCoarsening<2, dealii::LinearAlgebra::distributed::Vector<double, dealii::MemorySpace::Host> > >(dealii::SolverControl&, dealii::LinearAlgebra::distributed::Vector<double, dealii::MemorySpace::Host>&, dealii::LinearAlgebra::distributed::Vector<double, dealii::MemorySpace::Host> const&, GMGParameters const&, dealii::DoFHandler<2, 2> const&, Operator<2, double> const&, dealii::MGLevelObject<Operator<2, double> > const&, dealii::MGTransferGlobalCoarsening<2, dealii::LinearAlgebra::distributed::Vector<double, dealii::MemorySpace::Host> > const&) (solver_control=..., dst=..., src=..., mg_data=..., dof=..., fine_matrix=..., mg_matrices=..., mg_transfer=...)
    at /home/tamiko/workspace/dealii/tests/multigrid-global-coarsening/multigrid_util.h:398
#11 0x000055555586d61d in test<2, double>(unsigned int, unsigned int, bool, unsigned int) (n_refinements=3, fe_degree_fine=2, do_simplex_mesh=true, mesh_type=1)
    at /home/tamiko/workspace/dealii/tests/multigrid-global-coarsening/multigrid_p_01.cc:146
#12 0x00005555558525a2 in main(int, char**) (argc=1, argv=0x7fffffffdf48) at /home/tamiko/workspace/dealii/tests/multigrid-global-coarsening/multigrid_p_01.cc:205

This happened when executing the multigrid-global-coarsening/multigrid_p_01 test.

In reference to #15383

@kronbichler
Copy link
Member

I could reproduce this with valgrind:

==17471== Invalid read of size 4
==17471==    at 0x149B253C: dealii::AffineConstraints<double>::make_sorted_row_list(std::vector<unsigned int, std::allocator<unsigned int> > const&, std::vector<unsigned int, std::allocator<unsigned int> >&) const (deal.II/include/deal.II/lac/affine_constraints.templates.h:3847)
==17471==    by 0x149B1C69: dealii::AffineConstraints<double>::add_entries_local_to_global(std::vector<unsigned int, std::allocator<unsigned int> > const&, dealii::SparsityPatternBase&, bool, dealii::Table<2, bool> const&) const (deal.II/include/deal.II/lac/affine_constraints.templates.h:4320)
...
==17471==  Address 0x2f2e93ec is 4 bytes before a block of size 12 alloc'd
...
==17471==    by 0x1EDCD9: std::vector<unsigned int, std::allocator<unsigned int> >::_M_default_append(unsigned long) (vector.tcc:663)
==17471==    by 0x149B1C48: resize (stl_vector.h:1011)
==17471==    by 0x149B1C48: dealii::AffineConstraints<double>::add_entries_local_to_global(std::vector<unsigned int, std::allocator<unsigned int> > const&, dealii::SparsityPatternBase&, bool, dealii::Table<2, bool> const&) const (deal.II/include/deal.II/lac/affine_constraints.templates.h:4319)
==17471==    by 0x1494DCBC: void dealii::DoFTools::make_sparsity_pattern<2, 2, double>(dealii::DoFHandler<2, 2> const&, dealii::SparsityPatternBase&, dealii::AffineConstraints<double> const&, bool, unsigned int) (deal.II/source/dofs/dof_tools_sparsity.cc:103)
...

I will look into it now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants