[petsc-dev] MatCreateSubmatrices causes invalid memory write access in fortran

Tim Steinhoff kandanovian at gmail.com
Wed Apr 18 02:43:17 CDT 2018


Hi all,

with PETSc v3.9 there seems to be a out of bounds write in the fortran
interface of MatCreateSubmatrices.
https://bitbucket.org/petsc/petsc/src/59479656cffe26dd9a9d446f6d00dfe5e3168168/src/mat/interface/ftn-custom/zmatrixf.c?at=maint&fileviewer=file-view-default#zmatrixf.c-609

The reference mentions that in fortran one should pass a preallocated
array for submat with at least the size of m (actually it's probably a
typo and should be n)
http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatCreateSubMatrices.html

Then n+1 entries are copied into that array, where the last entry
seems to be some unneeded dummy (as mentioned).
for (i=0; i<=*n; i++) { /* lsmat[*n] might be a dummy matrix for
saving data struc */
  smat[i] = lsmat[i];
}
This leads to some bad errors afterwards, when that array is only of
the size of n as recommended.

Thanks and kind regards,

Volker


More information about the petsc-dev mailing list