Skip to content

[LinearSolver.Direct] EigenDirectSparseSolver: Fix out-of-bounds read on matrices with empty rows - #6258

Open
fredroy wants to merge 1 commit into
sofa-framework:masterfrom
fredroy:fix_eigensolver_matrixemptyrows
Open

[LinearSolver.Direct] EigenDirectSparseSolver: Fix out-of-bounds read on matrices with empty rows#6258
fredroy wants to merge 1 commit into
sofa-framework:masterfrom
fredroy:fix_eigensolver_matrixemptyrows

Conversation

@fredroy

@fredroy fredroy commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

advised by Claude while doing

its point:

copyNonZeros() does not store the rows which are entirely zero, so the filtered matrix held fewer row offsets than the Eigen::Map built from it reads, and the factorization accessed memory past the CRS arrays. fullRows() now restores those rows before the mapping.

Any remaining mismatch means the matrix contains entries outside its declared size ‚ CompressedRowSparseMatrix grows silently to store them , which is now reported instead of being mapped, the solver being left invalid so that solve() does not use an unfactorized Eigen solver.

I also instructed him to make unit tests to cover this case.

[with-all-tests]


By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).


Reviewers will merge this pull-request only if

  • it builds with SUCCESS for all platforms on the CI.
  • it does not generate new warnings.
  • it does not generate new unit test failures.
  • it does not generate new scene test failures.
  • it does not break API compatibility.
  • it is more than 1 week old (or has fast-merge label).

@fredroy fredroy added pr: fix Fix a bug pr: status to review To notify reviewers to review this pull-request pr: clean Cleaning the code pr: AI-aided Label notifying the reviewers that part or all of the PR has been generated with the help of an AI labels Aug 25, 2026

@alxbilger alxbilger left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I located a function in CompressedRowSparseMatrixGeneric.h that could be widely used wherever a CRS is manipulated, including in the solver of this PR: check_matrix. Currently, it's used nowhere. The problem is that this function implementation is suspect, there is no test and no documentation. I suggest to have a common tool (such as this function) to avoid testing code wherever a matrix is used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: AI-aided Label notifying the reviewers that part or all of the PR has been generated with the help of an AI pr: clean Cleaning the code pr: fix Fix a bug pr: status to review To notify reviewers to review this pull-request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants