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

Hong hzhang at mcs.anl.gov
Thu Apr 19 09:52:40 CDT 2018


Tim:
It is in the release branch
https://bitbucket.org/petsc/petsc/commits/f79229c73db120b69d05e6d49c19f429e09e633f
Thanks for reporting it.
Hong

Hong,
> we are fine with that. Thanks!
> Volker
>
> 2018-04-18 17:32 GMT+02:00 Hong <hzhang at mcs.anl.gov>:
> > Tim :
> >>
> >> 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/59479656cffe26dd9a9d446f6d00df
> e5e3168168/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.
> >
> >
> > We need this extra space for reuse -- I agree it makes Fortran API odd.
> >
> > I made following fix to the help manual:
> > diff --git a/src/mat/interface/matrix.c b/src/mat/interface/matrix.c
> >
> >     When finished using the submatrices, the user should destroy
> > -   them with MatDestroyMatrices().
> > +   them with MatDestroySubMatrices().
> >
> >     Fortran Note:
> >     The Fortran interface is slightly different from that given below; it
> > -   requires one to pass in  as submat a Mat (integer) array of size at
> > least m.
> > +   requires one to pass in  as submat a Mat (integer) array of size at
> > least n+1.
> >
> > If you agree, I'll push it to the petsc released version.
> >
> > Hong
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20180419/61d9a9d0/attachment.html>


More information about the petsc-dev mailing list