Audit finding
- ID:
AUD-012
- Status: Verified defect
- Severity: High
- Confidence: High
- Audited revision:
2f479320d805a1f9f35ebe4afaaeeded48913a94
Problem
CholeskyDecomposition::TryFactor() reads only the lower triangle and never validates symmetry or finite values.
Source:
|
OPTIMIZE_FOR_SPEED constexpr std::optional<SquareMatrix<T, N>> CholeskyDecomposition<T, N>::TryFactor(const SquareMatrix<T, N>& a) |
|
{ |
|
SquareMatrix<T, N> l{}; |
|
|
|
for (std::size_t i = 0; i < N; ++i) |
|
{ |
|
for (std::size_t j = 0; j <= i; ++j) |
|
{ |
|
const float sum = ToFloat(a.at(i, j)) - detail::CholeskyInnerProduct(l, i, j); |
|
|
|
if (i != j) |
|
l.at(i, j) = T(sum / ToFloat(l.at(j, j))); |
|
else if (sum <= std::numeric_limits<float>::epsilon() * math::Abs(ToFloat(a.at(i, i)))) |
|
return std::nullopt; |
|
else |
|
l.at(i, j) = T(math::Sqrt(sum)); |
|
} |
|
} |
|
|
|
return l; |
|
} |
|
|
|
template<typename T, std::size_t N> |
|
OPTIMIZE_FOR_SPEED constexpr SquareMatrix<T, N> CholeskyDecomposition<T, N>::Factor(const SquareMatrix<T, N>& a) |
Reproduction
[[4,100],[2,3]] returns an engaged optional. Its factor reconstructs [[4,2],[2,3]], not the supplied matrix. NaN pivots can also bypass the <= rejection comparison.
Acceptance criteria
Audit finding
AUD-0122f479320d805a1f9f35ebe4afaaeeded48913a94Problem
CholeskyDecomposition::TryFactor()reads only the lower triangle and never validates symmetry or finite values.Source:
numerical-toolbox-cpp/numerical/math/CholeskyDecomposition.hpp
Lines 42 to 65 in 2f47932
Reproduction
[[4,100],[2,3]]returns an engaged optional. Its factor reconstructs[[4,2],[2,3]], not the supplied matrix. NaN pivots can also bypass the<=rejection comparison.Acceptance criteria
A = L L^Treconstruction, nonsymmetric, NaN, and ill-conditioning tests.