Skip to content

Commit

Permalink
Merge pull request #15600 from tamiko/fix_scalapack
Browse files Browse the repository at this point in the history
lac/scalapack.cc: fix an out-of-bounds write that leads to a double free
  • Loading branch information
tamiko committed Jul 3, 2023
2 parents 7030a7a + 80323e7 commit 5398c13
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
7 changes: 7 additions & 0 deletions doc/news/9.4.0-vs-9.5.0.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,13 @@ inconvenience this causes.
<h3>Specific improvements</h3>
<ol>
<li>
Fixed: An out-of-bounds write due to an insufficiently sized buffer in
the Scalapack wrappers has been fixed.
<br>
(Matthias Maier, 2023/07/03)
</li>
<li>
Fixed: With some compilers, calling Threads::Task::Task() with a
function object that ends with an exception lead to a segmentation
Expand Down
14 changes: 12 additions & 2 deletions source/lac/scalapack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1592,8 +1592,18 @@ ScaLAPACKMatrix<NumberType>::eigenpairs_symmetric(
int liwork = -1;
NumberType *eigenvectors_loc =
(compute_eigenvectors ? eigenvectors->values.data() : nullptr);
work.resize(1);
iwork.resize(1);
/*
* According to the official "documentation" found on the internet
* (aka source file ppsyevx.f [1]) the work array has to have a
* minimal size of max(3, lwork). Because we query for optimal size
* (lwork == -1) we have to guarantee at least three doubles. The
* necessary size of iwork is not specified, so let's use three as
* well.
* [1]
* https://netlib.org/scalapack/explore-html/df/d1a/pdsyevx_8f_source.html
*/
work.resize(3);
iwork.resize(3);

if (all_eigenpairs)
{
Expand Down

0 comments on commit 5398c13

Please sign in to comment.