Skip to content

Commit ce3e4bd

Browse files
committed
Fixed an out-of-bounds read in convertSparseMatrix() when checking a mismatching sparse pattern
1 parent dbe6611 commit ce3e4bd

2 files changed

Lines changed: 9 additions & 19 deletions

File tree

‎NEWS.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# LMMsolver 1.0.14.9000
2+
3+
- Fixed an out-of-bounds read in `convertSparseMatrix()` when checking a sparse pattern mismatch.
4+
15
# LMMsolver 1.0.14
26

37
- Improved computational efficiency of supernodal Cholesky and its automatic differentiation.

‎src/LMMsolver_chol.cpp‎

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -166,37 +166,23 @@ NumericVector convertSparseMatrix(const SparseMatrix& A,
166166
int k = rowpointers[J + 1] - 1;
167167
int ndx = colpointers[j + 1] - 1;
168168

169-
for (int ll = A.rowpointers[j + 1] - 1; ll >= A.rowpointers[j]; ll--)
169+
const int kmin = rowpointers[J];
170+
171+
for (int ll = A.rowpointers[j + 1] - 1; ll >= A.rowpointers[j];ll--)
170172
{
171173
int c = A.colindices[ll];
172174

173175
if (c < j)
174176
break;
175177

176-
while (rowindices[k] != c)
178+
while (k >= kmin && rowindices[k] != c)
177179
{
178180
k--;
179181
ndx--;
180182
}
181183

182-
if (k < 0)
183-
{
184-
//Rcpp::Rcout << "\nPattern mismatch\n";
185-
//Rcpp::Rcout << "Column j = " << j
186-
// << ", searching for row c = " << c << "\n";
187-
188-
//Rcpp::Rcout << "\nSparseMatrix column rows: ";
189-
//for (int t = A.rowpointers[j]; t < A.rowpointers[j + 1]; t++)
190-
// Rcpp::Rcout << A.colindices[t] << " ";
191-
192-
//Rcpp::Rcout << "\nAD column rows: ";
193-
//for (int t = colpointers[j]; t < colpointers[j + 1]; t++)
194-
// Rcpp::Rcout << rowindices[t] << " ";
195-
196-
//Rcpp::Rcout << "\n";
197-
184+
if (k < kmin)
198185
Rcpp::stop("Pattern mismatch");
199-
}
200186

201187
result[ndx] = A.entries[ll];
202188

0 commit comments

Comments
 (0)