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

read_mtx() invalid read due to loop condition #453

Closed
brian-kelley opened this issue Aug 16, 2019 · 3 comments
Closed

read_mtx() invalid read due to loop condition #453

brian-kelley opened this issue Aug 16, 2019 · 3 comments

Comments

@brian-kelley
Copy link
Contributor

read_mtx() in KokkosKernels_IOUtils.hpp:998 loads a list of (row,col) pairs, sorts them, and then inserts into the CRS structure one row at a time. The loop over entries in the current row only checked if the next entry matches the current row, but NOT that the end of the pair array
has been reached. This caused an invalid read just after inserting the last entry in the matrix.

To fix this, I added another loop condition that makes sure eind < nE before reading edges[eind].

Valgrind output demonstrating the bug:

==59918== Invalid read of size 4
==59918==    at 0x43E819: int KokkosKernels::Impl::read_mtx<int, unsigned long, double>(char const*, int*, unsigned long*, unsigned long**, int**, double**, bool, bool, bool) (KokkosKernels_IOUtils.hpp:998)
==59918==    by 0x43F2FD: void KokkosKernels::Impl::read_matrix<int, unsigned long, double>(int*, unsigned long*, unsigned long**, int**, double**, char const*) (KokkosKernels_IOUtils.hpp:1019)
==59918==    by 0x43F480: KokkosSparse::CrsMatrix<double, int, Kokkos::Cuda, void, unsigned long> KokkosKernels::Impl::read_kokkos_crst_matrix<KokkosSparse::CrsMatrix<double, int, Kokkos::Cuda, void, unsigned long> >(char const*) (KokkosKernels_IOUtils.hpp:1055)
==59918==    by 0x405810: main (spgemm.cpp:55)
==59918==  Address 0xe169e50 is 0 bytes after a block of size 178,496 alloc'd
==59918==    at 0x4C2A1E3: operator new(unsigned long) (vg_replace_malloc.c:334)
==59918==    by 0x43DF9B: allocate (new_allocator.h:111)
==59918==    by 0x43DF9B: allocate (alloc_traits.h:436)
==59918==    by 0x43DF9B: _M_allocate (stl_vector.h:172)
==59918==    by 0x43DF9B: _M_create_storage (stl_vector.h:187)
==59918==    by 0x43DF9B: _Vector_base (stl_vector.h:138)
==59918==    by 0x43DF9B: vector (stl_vector.h:283)
==59918==    by 0x43DF9B: int KokkosKernels::Impl::read_mtx<int, unsigned long, double>(char const*, int*, unsigned long*, unsigned long**, int**, double**, bool, bool, bool) (KokkosKernels_IOUtils.hpp:933)
==59918==    by 0x43F2FD: void KokkosKernels::Impl::read_matrix<int, unsigned long, double>(int*, unsigned long*, unsigned long**, int**, double**, char const*) (KokkosKernels_IOUtils.hpp:1019)
==59918==    by 0x43F480: KokkosSparse::CrsMatrix<double, int, Kokkos::Cuda, void, unsigned long> KokkosKernels::Impl::read_kokkos_crst_matrix<KokkosSparse::CrsMatrix<double, int, Kokkos::Cuda, void, unsigned long> >(char const*) (KokkosKernels_IOUtils.hpp:1055)
==59918==    by 0x405810: main (spgemm.cpp:55)
@brian-kelley
Copy link
Contributor Author

Fix ready in #452, running spot check now.

@ndellingwood
Copy link
Contributor

@brian-kelley just for reference, was this related to reading one/some of the matrices as reported in #402 during issues with spgemm?

@brian-kelley
Copy link
Contributor Author

@ndellingwood I was running your spgemm driver with those matrices when I discovered this, but it would have happened with any matrix.

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

No branches or pull requests

2 participants