Conversation
`columnResult[row]` stores column `row` of the compliance matrix, so it must be sized by `J->rowSize()` (the number of constraint rows) and not by `J->colSize()` (the number of mechanical DOFs). Whenever the constraint row count exceeds the DOF count the scratch vector was written past its end, corrupting the heap in release builds (observed as `malloc(): corrupted top size`). Refs sofa-framework#6314 Signed-off-by: Igor <igorzubrycki@gmail.com>
Contributor
|
Hi @AdoHaha Thank you very much for your PR.
The reason you faced this issue and you came to fix it is also a plus. I added the flags for you and we will discuss the PR with the core devs. |
Author
|
@hugtalbot ok, next time I will write myself. Note that this was a bug caught during work on actual project: a balloon based device interacting with a plate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6314
Problem
MatrixLinearSolver<Matrix,Vector>::addJMInvJtLocalbuilds the compliance productfact * J M^-1 J^Twith one task per constraint row. Each task fillscolumnResult[row], which holds columnrowof the result, but the scratch vector was resized toJ->colSize()(the number of mechanical DOFs) while being indexed byrow2(the constraint row).buildComplianceMatrixsizesJas(result->rowSize(), systemMatrix->colSize()), soJ->rowSize()is the number of constraint rows. As soon as there are more constraint rows than DOFs — normal for contact-rich scenes —columnResult[row]is undersized and every column computation writes past its end.In release builds (
NDEBUG)FullVector::operator[]does not bounds-check, so this is silent heap corruption rather than a wrong result; in our simulations it surfaced asmalloc(): corrupted top sizefollowed by SIGABRT. The serial path (singleThreadAddJMInvJtLocal) is not affected because it uses the system RHS/solution vectors.Fix
Size the scratch column with
J->rowSize().FullVector::resizezero-initializes the buffer, so the existing+=accumulation remains correct.How it was tested
A minimal scene with one rigid body (6 DOFs) and
Nstatic spheres in contact (FrictionContactConstraint(mu=0.5), i.e.3Nconstraint rows), on v26.06.00 withEigenSimplicialLDLTandparallelInverseProduct=true:malloc(): corrupted top size→ SIGABRTmalloc(): corrupted top size→ SIGABRTRunning the same 10-sphere parallel case through the corrected routine (a local subclass changing only this line) does not abort, and its multipliers are exactly equal to the serial run (max abs difference 0.0). Script and logs: https://gist.github.com/AdoHaha/6ba87f1b18e194ad75722b1cce7ab199
I did not add a C++ unit test for this path:
addJMInvJtLocalrequires alinearSystemlink and an initialized task scheduler, so the reproduction above is an integration scene. I am happy to contribute a test if you can point me to the fixture you would prefer for solver/constraint-compliance tests.AI disclosure
The investigation and this patch were prepared with the help of an AI assistant. The failure was reproduced in a real simulation (contact problem with 940 constraint rows and 246 mechanical coordinates); the contributor reviewed the change. Per
CONTRIBUTING.md, this PR should carry thepr: AI-aidedlabel — I could not apply it because this account does not have permission to edit labels in this repository.By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).