root-project / root

The official repository for ROOT: analyzing, storing and visualizing big data, scientifically
https://root.cern
Other
2.68k stars 1.27k forks source link

[ROOT-2927] Particular instance of data causes segfault in TDecompSparse #14554

Open vepadulano opened 8 months ago

vepadulano commented 8 months ago

Check duplicate issues.

Description

From https://its.cern.ch/jira/browse/ROOT-2927

Dear ROOT,

I am attaching to this message a ROOT file that contains a sparse matrix, and a vector.

Trying to solve the equation formed by the two causes a segfault. The steps to reproduce the problem are the following:

$ root \-l matrix_fail.root
root [0]
Attaching file matrix_fail.root as _file0...
root [1] M
(class TMatrixTSparse<double>*)0xbed850
root [2] x
(class TVectorT<double>*)0xbedcb0
root [3] TDecompSparse solver(*M,0)
root [4] Bool_t ok
root [5] TVectorD xx = solver.Solve(*x, ok)

*** Break *** segmentation violation

The problem is due to this particular instance of the data: if you change one of the values of the x vector for example, you won't observe the segfault.

I have tried this in two different linux distributions (SL5 and ubuntu karmic) and two different ROOT versions (5.24 and 5.18), both 64 bits.

Reproducer

As per the description

ROOT version

Any

Installation method

Any

Operating system

Any

Additional context

Find input file in the Jira issue

ferdymercury commented 5 months ago

The crash happens on line 2598 of TDecompSparse.cxx:

w1 = w[ipiv]*a[apos];

because apos = 3493762

but fFact.N = 3493234

Not sure what the best way is to solve this, so pinging @lmoneta

The reproducer is:

#include "TFile.h"
#include "TDecompSparse.h"

void decomp() {
   auto f = TFile::Open("/tmp/matrix_fail.root");
   f->ls();
   TMatrixTSparse<double>* M = (TMatrixTSparse<double>*)f->Get("M");
   M->Print();
   TVectorT<double>* x = (TVectorT<double>*)f->Get("x");
   TDecompSparse solver(*M,0);
   Bool_t ok;
   TVectorD xx = solver.Solve(*x, ok);
}