Coverage Report

Created: 2026-02-27 06:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/solver_fuzzer.cc
Line
Count
Source
1
// Copyright 2019 Google LLC
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//      http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#include <cstddef>
16
#include <cstdint>
17
#include <cstdlib>
18
#include <string>
19
20
#include "Eigen/Core"
21
22
using ::Eigen::Matrix;
23
using ::Eigen::Dynamic;
24
using ::Eigen::Lower;
25
using ::Eigen::Upper;
26
27
23.9M
int ConsumeNextInt(const uint8_t** data, size_t* size) {
28
23.9M
  if (*size < sizeof(int)) {
29
23.6M
    return 0;
30
23.6M
  }
31
230k
  int result;
32
230k
  memcpy(&result, *data, sizeof(int));
33
230k
  *size -= sizeof(int);
34
230k
  *data += sizeof(int);
35
230k
  return result;
36
23.9M
}
37
38
360
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
39
360
  const size_t rows = static_cast<size_t>(ConsumeNextInt(&data, &size));
40
360
  const size_t columns = static_cast<size_t>(ConsumeNextInt(&data, &size));
41
42
360
  if (rows == 0 || columns == 0) {
43
86
    return 0;
44
86
  }
45
274
  if (rows > 1024 || columns > 1024) {
46
119
    return 0;
47
119
  }
48
49
  // We can do this same fuzz test with other templated types. Here, we just use
50
  // an int.
51
155
  Matrix<int, Dynamic, 1> vec(rows);
52
50.3k
  for (size_t i = 0; i < rows; ++i) {
53
50.2k
    vec(i) = ConsumeNextInt(&data, &size);
54
50.2k
  }
55
155
  Matrix<int, Dynamic, Dynamic> matrix(rows, columns);
56
50.3k
  for (int i = 0; i < rows; ++i) {
57
23.9M
    for (int j = 0; j < columns; ++j) {
58
23.8M
      matrix(i, j) = ConsumeNextInt(&data, &size);
59
23.8M
    }
60
50.2k
  }
61
62
155
  matrix.template triangularView<Lower>().solve(vec);
63
155
  matrix.template triangularView<Upper>().solve(vec);
64
155
  matrix.conjugate().template triangularView<Lower>().solve(vec);
65
155
  matrix.conjugate().template triangularView<Upper>().solve(vec);
66
155
  matrix.transpose().template triangularView<Lower>().solve(vec);
67
155
  matrix.transpose().template triangularView<Upper>().solve(vec);
68
69
155
  return 0;
70
274
}