Skip to content

[AUD-012][High] Reject nonsymmetric and non-finite Cholesky input #310

Description

@gabrielsantosphilips

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

  • Reject nonsymmetric input using a scale-aware float tolerance.
  • Reject NaN and infinite values.
  • Preserve a recoverable failure result through callers.
  • Add A = L L^T reconstruction, nonsymmetric, NaN, and ill-conditioning tests.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions