Skip to content

GCC UBSAN error when a sparse matrix is constructed

Submitted by Yixuan Qiu

Assigned to Nobody

Link to original bugzilla bug (#1170)
Version: 3.2

Description

Hi All,
GCC UBSAN reports runtime errors when a sparse matrix is copied. Below is a minimal example:

========================================
#include <Eigen/Sparse>

int main()
{
int m = 3;
int n = 3;
int nnz = 3;
int outter[] = {0, 1, 2, 3};
int inner[] = {0, 1, 2};
double x[] = {1.0, 2.0, 3.0};

Eigen::MappedSparseMatrix&lt;double&gt; mat(m, n, nnz, outter, inner, x);  

Eigen::SparseMatrix&lt;double&gt; mat2 = mat; // This line causes UBSAN error  

return 0;  

}

========================================

Compiling this code with "g++ -g -fsanitize=undefined,address -I. test.cpp" and running it gives

Eigen/src/Core/util/Memory.h:510:5: runtime error: null pointer passed as argument 2, which is declared to never be null
Eigen/src/Core/util/Memory.h:510:5: runtime error: null pointer passed as argument 2, which is declared to never be null

This traces back to line 510 of Eigen/src/Core/util/Memory.h, which is a call of memcpy().

When commenting out the line of constructing mat2 from mat, this error does not occur, so I guess there was an attempt to copy data from a null pointer when a sparse matrix is constructed.

Thanks!

OS: Fedora 23 64-bit
Eigen: 3.2.8
GCC: g++ (GCC) 5.3.1 20151207 (Red Hat 5.3.1-2)

Edited by Eigen Bugzilla