/src/alembic_dump_info_fuzzer.cc
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2020 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 <err.h> |
16 | | #include <errno.h> |
17 | | #include <fcntl.h> |
18 | | #include <stddef.h> |
19 | | #include <stdint.h> |
20 | | #include <stdlib.h> |
21 | | #include <string.h> |
22 | | #include <unistd.h> |
23 | | |
24 | | #include "alembic/lib/Alembic/AbcCoreFactory/All.h" |
25 | | #include "alembic/lib/Alembic/AbcCoreOgawa/All.h" |
26 | | #include "alembic/lib/Alembic/AbcGeom/All.h" |
27 | | #include "alembic/lib/Alembic/AbcMaterial/All.h" |
28 | | |
29 | | #include "fuzzer_temp_file.h" |
30 | | |
31 | | using Alembic::AbcCoreAbstract::PropertyHeader; |
32 | | using Alembic::AbcCoreAbstract::PropertyType; |
33 | | using Alembic::AbcCoreFactory::IFactory; |
34 | | using Alembic::AbcGeom::C4fArraySamplePtr; |
35 | | using Alembic::AbcGeom::IArchive; |
36 | | using Alembic::AbcGeom::IC4fGeomParam; |
37 | | using Alembic::AbcGeom::ICompoundProperty; |
38 | | using Alembic::AbcGeom::ICurves; |
39 | | using Alembic::AbcGeom::ICurvesSchema; |
40 | | using Alembic::AbcGeom::IFaceSet; |
41 | | using Alembic::AbcGeom::IFaceSetSchema; |
42 | | using Alembic::AbcGeom::IGeomBaseSchema; |
43 | | using Alembic::AbcGeom::IN3fGeomParam; |
44 | | using Alembic::AbcGeom::index_t; |
45 | | using Alembic::AbcGeom::Int32ArraySamplePtr; |
46 | | using Alembic::AbcGeom::IObject; |
47 | | using Alembic::AbcGeom::IPolyMesh; |
48 | | using Alembic::AbcGeom::IPolyMeshSchema; |
49 | | using Alembic::AbcGeom::ISubD; |
50 | | using Alembic::AbcGeom::ISubDSchema; |
51 | | using Alembic::AbcGeom::IV2fGeomParam; |
52 | | using Alembic::AbcGeom::IXform; |
53 | | using Alembic::AbcGeom::IXformSchema; |
54 | | using Alembic::AbcGeom::M44d; |
55 | | using Alembic::AbcGeom::M44f; |
56 | | using Alembic::AbcGeom::N3fArraySamplePtr; |
57 | | using Alembic::AbcGeom::ObjectHeader; |
58 | | using Alembic::AbcGeom::P3fArraySamplePtr; |
59 | | using Alembic::AbcGeom::UInt32ArraySamplePtr; |
60 | | using Alembic::AbcGeom::V2fArraySamplePtr; |
61 | | using Alembic::AbcMaterial::IMaterial; |
62 | | using Alembic::AbcMaterial::IMaterialSchema; |
63 | | |
64 | 0 | template <typename T> void dumpAttributes(T const &schema) { |
65 | |
|
66 | 0 | const size_t meshPropertyCount = schema.getNumProperties(); |
67 | |
|
68 | 0 | for (size_t p = 0; p < meshPropertyCount; p++) { |
69 | 0 | const PropertyHeader &header = schema.getPropertyHeader(p); |
70 | 0 | const PropertyType pType = header.getPropertyType(); |
71 | 0 | const std::string &name = header.getName(); |
72 | |
|
73 | 0 | if (name == "P") { |
74 | 0 | schema.getNumSamples(); |
75 | 0 | } else if (name == "uv" || name == "st") { |
76 | 0 | schema.getUVsParam().getNumSamples(); |
77 | 0 | } else if (name == ".arbGeomParams") { |
78 | | // additional geometry elements (color sets, additional texture |
79 | | // coordinates) |
80 | 0 | const ICompoundProperty geoParam = schema.getArbGeomParams(); |
81 | 0 | const size_t geoPropCount = geoParam.getNumProperties(); |
82 | |
|
83 | 0 | for (size_t g = 0; g < geoPropCount; g++) { |
84 | 0 | const PropertyHeader &headerGeo = geoParam.getPropertyHeader(g); |
85 | 0 | const std::string &nameGeo = headerGeo.getName(); |
86 | 0 | } |
87 | 0 | } |
88 | 0 | } |
89 | 0 | } Unexecuted instantiation: void dumpAttributes<Alembic::AbcGeom::v12::IPolyMeshSchema>(Alembic::AbcGeom::v12::IPolyMeshSchema const&) Unexecuted instantiation: void dumpAttributes<Alembic::AbcGeom::v12::ISubDSchema>(Alembic::AbcGeom::v12::ISubDSchema const&) Unexecuted instantiation: void dumpAttributes<Alembic::AbcGeom::v12::ICurvesSchema>(Alembic::AbcGeom::v12::ICurvesSchema const&) |
90 | | |
91 | 0 | void dumpPolyMesh(const IObject &node) { |
92 | 0 | const ObjectHeader &header = node.getHeader(); |
93 | 0 | const IPolyMesh mesh(node.getParent(), header.getName()); |
94 | 0 | const IPolyMeshSchema &schema = mesh.getSchema(); |
95 | | |
96 | | // Mesh properties |
97 | 0 | dumpAttributes(schema); |
98 | 0 | } |
99 | | |
100 | 0 | void dumpSubD(const IObject &node) { |
101 | 0 | const ObjectHeader &header = node.getHeader(); |
102 | 0 | const ISubD mesh(node.getParent(), header.getName()); |
103 | 0 | const ISubDSchema &schema = mesh.getSchema(); |
104 | |
|
105 | 0 | dumpAttributes(schema); |
106 | 0 | schema.getSubdivisionSchemeProperty(); |
107 | 0 | schema.getFaceVaryingInterpolateBoundaryProperty(); |
108 | 0 | schema.getFaceVaryingPropagateCornersProperty(); |
109 | 0 | schema.getInterpolateBoundaryProperty(); |
110 | 0 | } |
111 | | |
112 | 0 | void dumpFaceSet(const IObject &node) { |
113 | 0 | const ObjectHeader &header = node.getHeader(); |
114 | 0 | const IFaceSet faceSet(node.getParent(), header.getName()); |
115 | 0 | const IFaceSetSchema &schema = faceSet.getSchema(); |
116 | 0 | schema.getNumSamples(); |
117 | 0 | } |
118 | | |
119 | 0 | void dumpCurves(const IObject &node) { |
120 | 0 | const ObjectHeader &header = node.getHeader(); |
121 | 0 | const ICurves curves(node.getParent(), header.getName()); |
122 | 0 | const ICurvesSchema &schema = curves.getSchema(); |
123 | |
|
124 | 0 | dumpAttributes(schema); |
125 | 0 | } |
126 | | |
127 | 0 | void dumpXform(const IObject &node) { |
128 | 0 | const ObjectHeader &header = node.getHeader(); |
129 | 0 | const IXform xform(node.getParent(), header.getName()); |
130 | 0 | const IXformSchema &schema = xform.getSchema(); |
131 | |
|
132 | 0 | schema.getNumSamples(); |
133 | 0 | schema.getNumOps(); |
134 | 0 | } |
135 | | |
136 | 0 | void dumpMaterial(const IObject &node) { |
137 | 0 | const ObjectHeader &header = node.getHeader(); |
138 | 0 | IMaterial material(node.getParent(), header.getName()); |
139 | 0 | IMaterialSchema &schema = material.getSchema(); |
140 | |
|
141 | 0 | std::vector<std::string> targetNames; |
142 | 0 | schema.getTargetNames(targetNames); |
143 | |
|
144 | 0 | for (const std::string &target : targetNames) { |
145 | 0 | std::vector<std::string> shaderTypes; |
146 | 0 | schema.getShaderTypesForTarget(target, shaderTypes); |
147 | 0 | const size_t shaderTypeCount = shaderTypes.size(); |
148 | 0 | for (size_t s = 0; s < shaderTypeCount; s++) { |
149 | |
|
150 | 0 | ICompoundProperty parameters = |
151 | 0 | schema.getShaderParameters(target, shaderTypes[s]); |
152 | 0 | const size_t parameterCount = parameters.getNumProperties(); |
153 | 0 | } |
154 | 0 | } |
155 | 0 | } |
156 | | |
157 | 37 | void dumpNodes(const IObject &node) { |
158 | 37 | const ObjectHeader &header = node.getHeader(); |
159 | | // Dump the general node information. |
160 | 37 | header.getName(); |
161 | 37 | header.getFullName(); |
162 | 37 | header.getMetaData().serialize(); |
163 | | |
164 | | // Dump the type specific information. |
165 | 37 | if (Alembic::AbcGeom::IPolyMesh::matches(header)) { |
166 | 0 | dumpPolyMesh(node); |
167 | 37 | } else if (Alembic::AbcGeom::ISubD::matches(header)) { |
168 | 0 | dumpSubD(node); |
169 | 37 | } else if (Alembic::AbcGeom::IFaceSet::matches(header)) { |
170 | 0 | dumpFaceSet(node); |
171 | 37 | } else if (Alembic::AbcGeom::ICurves::matches(header)) { |
172 | 0 | dumpCurves(node); |
173 | 37 | } else if (Alembic::AbcGeom::IXform::matches(header)) { |
174 | 0 | dumpXform(node); |
175 | 37 | } else if (Alembic::AbcMaterial::IMaterial::matches(header)) { |
176 | 0 | dumpMaterial(node); |
177 | 37 | } else { // Miscellaneous nodes such as the root. |
178 | 37 | ; |
179 | 37 | } |
180 | | |
181 | | // Dump the child headers. |
182 | 37 | const size_t childCount = node.getNumChildren(); |
183 | 37 | for (size_t i = 0; i < childCount; i++) { |
184 | 0 | dumpNodes(node.getChild(i)); |
185 | 0 | } |
186 | 37 | } |
187 | | |
188 | 277 | void dumpInfo(const char *file) { |
189 | | // Load the Alembic archive and verify that it is valid. |
190 | 277 | IFactory factory; |
191 | 277 | IArchive archive = factory.getArchive(file); |
192 | | |
193 | 277 | if (archive.valid()) { |
194 | 37 | archive.getName(); |
195 | 37 | dumpNodes(archive.getTop()); |
196 | 37 | } |
197 | 277 | } |
198 | | |
199 | 277 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
200 | 277 | FuzzerTemporaryFile tempFile(data, size); |
201 | 277 | dumpInfo(tempFile.filename()); |
202 | | |
203 | 277 | return 0; |
204 | 277 | } |