Line | Count | Source |
1 | | // Copyright 2026 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 <fuzzer/FuzzedDataProvider.h> |
16 | | #include <Eigen/Core> |
17 | | #include <Eigen/Geometry> |
18 | | |
19 | | namespace { |
20 | | |
21 | | template <typename Scalar> |
22 | 984 | void fuzzGeometry(FuzzedDataProvider* stream) { |
23 | 984 | typedef Eigen::Matrix<Scalar, 3, 1> Vector3; |
24 | 984 | typedef Eigen::Quaternion<Scalar> Quaternion; |
25 | 984 | typedef Eigen::AngleAxis<Scalar> AngleAxis; |
26 | 984 | typedef Eigen::Rotation2D<Scalar> Rotation2D; |
27 | 984 | typedef Eigen::Transform<Scalar, 3, Eigen::Affine> Transform3; |
28 | | |
29 | 984 | Vector3 v1(stream->ConsumeFloatingPoint<Scalar>(), |
30 | 984 | stream->ConsumeFloatingPoint<Scalar>(), |
31 | 984 | stream->ConsumeFloatingPoint<Scalar>()); |
32 | 984 | Vector3 v2(stream->ConsumeFloatingPoint<Scalar>(), |
33 | 984 | stream->ConsumeFloatingPoint<Scalar>(), |
34 | 984 | stream->ConsumeFloatingPoint<Scalar>()); |
35 | | |
36 | | // Quaternions |
37 | 984 | Quaternion q1(stream->ConsumeFloatingPoint<Scalar>(), |
38 | 984 | stream->ConsumeFloatingPoint<Scalar>(), |
39 | 984 | stream->ConsumeFloatingPoint<Scalar>(), |
40 | 984 | stream->ConsumeFloatingPoint<Scalar>()); |
41 | 984 | q1.normalize(); |
42 | 984 | Quaternion q2(stream->ConsumeFloatingPoint<Scalar>(), |
43 | 984 | stream->ConsumeFloatingPoint<Scalar>(), |
44 | 984 | stream->ConsumeFloatingPoint<Scalar>(), |
45 | 984 | stream->ConsumeFloatingPoint<Scalar>()); |
46 | 984 | q2.normalize(); |
47 | | |
48 | 984 | (void)q1.slerp(stream->ConsumeFloatingPoint<Scalar>(), q2); |
49 | 984 | (void)q1.inverse(); |
50 | 984 | (void)q1.conjugate(); |
51 | 984 | (void)(q1 * q2); |
52 | 984 | (void)(q1 * v1); |
53 | | |
54 | | // AngleAxis |
55 | 984 | AngleAxis aa1(stream->ConsumeFloatingPoint<Scalar>(), v1.normalized()); |
56 | 984 | (void)aa1.toRotationMatrix(); |
57 | 984 | (void)Quaternion(aa1); |
58 | | |
59 | | // Transform |
60 | 984 | Transform3 t1 = Transform3::Identity(); |
61 | 984 | t1.translate(v1); |
62 | 984 | t1.rotate(q1); |
63 | 984 | t1.scale(stream->ConsumeFloatingPoint<Scalar>()); |
64 | | |
65 | 984 | (void)(t1 * v2); |
66 | 984 | (void)t1.inverse(); |
67 | | |
68 | | // Hyperplane |
69 | 984 | Eigen::Hyperplane<Scalar, 3> hp(v1.normalized(), stream->ConsumeFloatingPoint<Scalar>()); |
70 | 984 | (void)hp.absDistance(v2); |
71 | 984 | (void)hp.projection(v2); |
72 | | |
73 | | // ParametrizedLine |
74 | 984 | Eigen::ParametrizedLine<Scalar, 3> line(v1, v2.normalized()); |
75 | 984 | (void)line.distance(v2); |
76 | 984 | (void)line.projection(v2); |
77 | 984 | } geometry_fuzzer.cc:void (anonymous namespace)::fuzzGeometry<float>(FuzzedDataProvider*) Line | Count | Source | 22 | 514 | void fuzzGeometry(FuzzedDataProvider* stream) { | 23 | 514 | typedef Eigen::Matrix<Scalar, 3, 1> Vector3; | 24 | 514 | typedef Eigen::Quaternion<Scalar> Quaternion; | 25 | 514 | typedef Eigen::AngleAxis<Scalar> AngleAxis; | 26 | 514 | typedef Eigen::Rotation2D<Scalar> Rotation2D; | 27 | 514 | typedef Eigen::Transform<Scalar, 3, Eigen::Affine> Transform3; | 28 | | | 29 | 514 | Vector3 v1(stream->ConsumeFloatingPoint<Scalar>(), | 30 | 514 | stream->ConsumeFloatingPoint<Scalar>(), | 31 | 514 | stream->ConsumeFloatingPoint<Scalar>()); | 32 | 514 | Vector3 v2(stream->ConsumeFloatingPoint<Scalar>(), | 33 | 514 | stream->ConsumeFloatingPoint<Scalar>(), | 34 | 514 | stream->ConsumeFloatingPoint<Scalar>()); | 35 | | | 36 | | // Quaternions | 37 | 514 | Quaternion q1(stream->ConsumeFloatingPoint<Scalar>(), | 38 | 514 | stream->ConsumeFloatingPoint<Scalar>(), | 39 | 514 | stream->ConsumeFloatingPoint<Scalar>(), | 40 | 514 | stream->ConsumeFloatingPoint<Scalar>()); | 41 | 514 | q1.normalize(); | 42 | 514 | Quaternion q2(stream->ConsumeFloatingPoint<Scalar>(), | 43 | 514 | stream->ConsumeFloatingPoint<Scalar>(), | 44 | 514 | stream->ConsumeFloatingPoint<Scalar>(), | 45 | 514 | stream->ConsumeFloatingPoint<Scalar>()); | 46 | 514 | q2.normalize(); | 47 | | | 48 | 514 | (void)q1.slerp(stream->ConsumeFloatingPoint<Scalar>(), q2); | 49 | 514 | (void)q1.inverse(); | 50 | 514 | (void)q1.conjugate(); | 51 | 514 | (void)(q1 * q2); | 52 | 514 | (void)(q1 * v1); | 53 | | | 54 | | // AngleAxis | 55 | 514 | AngleAxis aa1(stream->ConsumeFloatingPoint<Scalar>(), v1.normalized()); | 56 | 514 | (void)aa1.toRotationMatrix(); | 57 | 514 | (void)Quaternion(aa1); | 58 | | | 59 | | // Transform | 60 | 514 | Transform3 t1 = Transform3::Identity(); | 61 | 514 | t1.translate(v1); | 62 | 514 | t1.rotate(q1); | 63 | 514 | t1.scale(stream->ConsumeFloatingPoint<Scalar>()); | 64 | | | 65 | 514 | (void)(t1 * v2); | 66 | 514 | (void)t1.inverse(); | 67 | | | 68 | | // Hyperplane | 69 | 514 | Eigen::Hyperplane<Scalar, 3> hp(v1.normalized(), stream->ConsumeFloatingPoint<Scalar>()); | 70 | 514 | (void)hp.absDistance(v2); | 71 | 514 | (void)hp.projection(v2); | 72 | | | 73 | | // ParametrizedLine | 74 | 514 | Eigen::ParametrizedLine<Scalar, 3> line(v1, v2.normalized()); | 75 | 514 | (void)line.distance(v2); | 76 | 514 | (void)line.projection(v2); | 77 | 514 | } |
geometry_fuzzer.cc:void (anonymous namespace)::fuzzGeometry<double>(FuzzedDataProvider*) Line | Count | Source | 22 | 470 | void fuzzGeometry(FuzzedDataProvider* stream) { | 23 | 470 | typedef Eigen::Matrix<Scalar, 3, 1> Vector3; | 24 | 470 | typedef Eigen::Quaternion<Scalar> Quaternion; | 25 | 470 | typedef Eigen::AngleAxis<Scalar> AngleAxis; | 26 | 470 | typedef Eigen::Rotation2D<Scalar> Rotation2D; | 27 | 470 | typedef Eigen::Transform<Scalar, 3, Eigen::Affine> Transform3; | 28 | | | 29 | 470 | Vector3 v1(stream->ConsumeFloatingPoint<Scalar>(), | 30 | 470 | stream->ConsumeFloatingPoint<Scalar>(), | 31 | 470 | stream->ConsumeFloatingPoint<Scalar>()); | 32 | 470 | Vector3 v2(stream->ConsumeFloatingPoint<Scalar>(), | 33 | 470 | stream->ConsumeFloatingPoint<Scalar>(), | 34 | 470 | stream->ConsumeFloatingPoint<Scalar>()); | 35 | | | 36 | | // Quaternions | 37 | 470 | Quaternion q1(stream->ConsumeFloatingPoint<Scalar>(), | 38 | 470 | stream->ConsumeFloatingPoint<Scalar>(), | 39 | 470 | stream->ConsumeFloatingPoint<Scalar>(), | 40 | 470 | stream->ConsumeFloatingPoint<Scalar>()); | 41 | 470 | q1.normalize(); | 42 | 470 | Quaternion q2(stream->ConsumeFloatingPoint<Scalar>(), | 43 | 470 | stream->ConsumeFloatingPoint<Scalar>(), | 44 | 470 | stream->ConsumeFloatingPoint<Scalar>(), | 45 | 470 | stream->ConsumeFloatingPoint<Scalar>()); | 46 | 470 | q2.normalize(); | 47 | | | 48 | 470 | (void)q1.slerp(stream->ConsumeFloatingPoint<Scalar>(), q2); | 49 | 470 | (void)q1.inverse(); | 50 | 470 | (void)q1.conjugate(); | 51 | 470 | (void)(q1 * q2); | 52 | 470 | (void)(q1 * v1); | 53 | | | 54 | | // AngleAxis | 55 | 470 | AngleAxis aa1(stream->ConsumeFloatingPoint<Scalar>(), v1.normalized()); | 56 | 470 | (void)aa1.toRotationMatrix(); | 57 | 470 | (void)Quaternion(aa1); | 58 | | | 59 | | // Transform | 60 | 470 | Transform3 t1 = Transform3::Identity(); | 61 | 470 | t1.translate(v1); | 62 | 470 | t1.rotate(q1); | 63 | 470 | t1.scale(stream->ConsumeFloatingPoint<Scalar>()); | 64 | | | 65 | 470 | (void)(t1 * v2); | 66 | 470 | (void)t1.inverse(); | 67 | | | 68 | | // Hyperplane | 69 | 470 | Eigen::Hyperplane<Scalar, 3> hp(v1.normalized(), stream->ConsumeFloatingPoint<Scalar>()); | 70 | 470 | (void)hp.absDistance(v2); | 71 | 470 | (void)hp.projection(v2); | 72 | | | 73 | | // ParametrizedLine | 74 | 470 | Eigen::ParametrizedLine<Scalar, 3> line(v1, v2.normalized()); | 75 | 470 | (void)line.distance(v2); | 76 | 470 | (void)line.projection(v2); | 77 | 470 | } |
|
78 | | |
79 | | } // namespace |
80 | | |
81 | 984 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
82 | 984 | FuzzedDataProvider stream(data, size); |
83 | | |
84 | 984 | uint8_t type = stream.ConsumeIntegral<uint8_t>(); |
85 | 984 | if (type % 2 == 0) { |
86 | 514 | fuzzGeometry<float>(&stream); |
87 | 514 | } else { |
88 | 470 | fuzzGeometry<double>(&stream); |
89 | 470 | } |
90 | | |
91 | 984 | return 0; |
92 | 984 | } |