SparseLU .solve() crashes for various input
Submitted by Andreas Longva
Assigned to Nobody
Link to original bugzilla bug (#1356)
Version: 3.3 (current stable)
Description
Created attachment 756
Minimal testcase
I've attached a minimal testcase which demonstrates the problem. When compiling with -fsanitize=undefined, a runtime error is recorded. In this minimal test case, it seems that the code is able to recover and produce some output (presumably it is correct? Haven't checked). However, in my larger real-world examples, it crashes with segmentation faults outright in release builds in which I have not enabled fsanitize. I've reprinted the code, compile output and output from running the example below, including the compiler versions of G++ and clang++ that I tested it with.
Code:
#include <Eigen/Sparse>
#include <Eigen/SparseLU>
#include <iostream>
int main()
{
Eigen::SparseMatrix<double> mat(4, 4);
mat.coeffRef(0,0) = 4;
mat.coeffRef(1,0) = -1;
mat.coeffRef(2, 0) = -1;
mat.coeffRef(3, 0) = 0.87499999999999978;
mat.coeffRef(0, 1) = -1;
mat.coeffRef(1, 1) = 4;
mat.coeffRef(2, 1) = 0;
mat.coeffRef(3, 1) = 0.125;
mat.coeffRef(0, 2) = -1;
mat.coeffRef(1, 2) = 0;
mat.coeffRef(2, 2) = 4;
mat.coeffRef(3, 2) = 0.1249999999999999;
mat.coeffRef(0, 3) = 0.87499999999999978;
mat.coeffRef(1, 3) = 0.125;
mat.coeffRef(2, 3) = 0.1249999999999999;
mat.coeffRef(3, 3) = 0;
Eigen::VectorXd b(4);
b(0) = -0.5;
b(1) = 0.0;
b(2) = 0.0;
b(3) = 0.0;
Eigen::SparseLU<Eigen::SparseMatrix<double>> solver;
solver.analyzePattern(mat);
solver.factorize(mat);
Eigen::VectorXd sol(4);
sol = solver.solve(b);
std::cout << sol << std::endl;
return 0;
}
Running make
:
$ make
clang++ -fsanitize=undefined -std=c++11 -o eigen_testcase_clang eigen_testcase.cpp
g++ -fsanitize=undefined -std=c++11 -o eigen_testcase_gcc eigen_testcase.cpp
Running the test binaries for each compiler:
$ ./eigen_testcase_clang
/usr/local/include/Eigen/src/Core/CoreEvaluators.h:181:14: runtime error: reference binding to null pointer of type 'Scalar' (aka 'double')
-0.00431034
0.0150862
0.0150862
-0.517241
$ ./eigen_testcase_gcc
/usr/local/include/Eigen/src/Core/CoreEvaluators.h:181:75: runtime error: reference binding to null pointer of type 'Scalar'
-0.00431034
0.0150862
0.0150862
-0.517241
Compiler versions:
$ g++ --version
g++ (Ubuntu 5.2.1-22ubuntu2) 5.2.1 20151010
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ clang++ --version
Ubuntu clang version 3.6.2-1 (tags/RELEASE_362/final) (based on LLVM 3.6.2)
Target: x86_64-pc-linux-gnu
Thread model: posix
Attachment 756, "Minimal testcase":
eigen_testcase.tar