Repository navigation
Bound glTF point cloud and mesh builder writes - #1277
Open
makstrogonpl wants to merge 1 commit into
Open
makstrogonpl wants to merge 1 commit into
makstrogonpl wants to merge 1 commit into
Conversation
Point cloud builders were started with one point per index, but values were written at the point given by each index value. Valid glTF files with point primitives, morph targets or joints whose index values are greater than or equal to the number of indices wrote past the end of the attribute buffers. * Check every builder write against the number of faces or points the builder was started with (SetValuesForBuilder, SetValuesPerFace and the material writers). Adds PointCloudBuilder::num_points() and TriangleSoupMeshBuilder::num_faces(). * Store plain point primitives in the order given by the indices, one point per index. * Primitives with morph targets or joints keep the input vertex ids. Their point clouds are sized to hold the largest referenced vertex, limited by the accessor counts that are backed by buffer data. Adds three test files and two unit tests.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
>=the number of indices writes past the attribute buffer (heap buffer overflow write).GltfDecoder::DecodeFromFileToScene(draco_transcoder) andDecodeFromFile.src/draco/io/gltf_decoder.cc,src/draco/io/gltf_decoder.h,src/draco/mesh/triangle_soup_mesh_builder.h,src/draco/point_cloud/point_cloud_builder.h,src/draco/io/gltf_decoder_test.cc.Problem
When the glTF decoder builds a point cloud, it starts the builder with one point per index but writes each value at the point given by the index value:
Whenever an index value is greater than or equal to the number of indices, the write lands past the end of the attribute buffer.
This needs no malformed input. The following files are valid glTF 2.0 (they pass the Khronos validator) and overflow the heap:
POINTSprimitive with indices[5, 7]into 8 vertices;TRIANGLESprimitive withJOINTS_0/WEIGHTS_0or with morph targets, whose triangle uses the last three vertices of a 24-vertex buffer. Such primitives are decoded through the point cloud builder to keep vertex ids.It happens whenever the largest index of such a primitive is not smaller than its number of indices, for example when several primitives share one vertex buffer and a small primitive uses its upper part.
Consequences
Heap buffer overflow write in
PointCloudBuilder::SetAttributeValueForPoint, reachable fromGltfDecoder::DecodeFromFileToScene(draco_transcoder) andDecodeFromFile(draco_encoder). The written data comes from the file's vertex attributes.draco_transcoderfrom the Debian 13 package (1.5.6) behaves this way for the point and skinned files.draco_transcoderwith SIGSEGV.I am aware
SECURITY.mdsays the glTF path is not hardened for untrusted input. This one is hit by valid files, so it is also a correctness bug: such models cannot be transcoded reliably today.Reproduce on
main(d6c1acf)Sanitizer output (point model)
Fix
SetValuesForBuilder(point cloud),SetValuesPerFaceand both material writers refuse to write outside the points or faces the builder was started with. This adds two const accessors,PointCloudBuilder::num_points()andTriangleSoupMeshBuilder::num_faces().igets the value of vertexindices[i]. This matches how the builder is sized and how the material writer already numbers points.keep_vertex_ids_). Their point clouds are started with at least one point per index and up tomax(index) + 1points, limited by the smallest accessor count that is backed by buffer data, and not raised at all when an attribute that will be decoded has no valid data. A claimed count therefore cannot enlarge the allocation.Behavior change
Point primitives with indices that are not
0..n-1now produce their points in index order, without unreferenced vertices. Before, they were written in vertex order and overflowed when an index value exceeded the index count. Files without indices, or with indices0..n-1, produce byte-identical output.Verification
TestPointPrimitiveWithSparseIndices,TestSkinAndMorphPrimitivesWithHighIndicesmain, pass with the changemain, anddraco_transcoder.exewrites a wrong-sized file for the morph model without reporting an error; with the change the tests pass and the three models convert to the same sizes as on Linuxmain, 0 with the change, no valid variant rejectedmain; 0 with the change, vertex ids, faces and morph data correct in all 400testdata/throughdraco_encoderanddraco_transcoderPerformance
draco_transcodermainDragonAttenuation.glb(6.4 MB)SheenCloth.glb(3.9 MB)CesiumMan.glb(479 KB, skinned)Duck.glb(117 KB)Release build, macOS/clang, median of 25 runs, this change alone against
main. Output files are byte-identical.The variant numbers were measured together with the companion change for glTF input checks.
New test files:
testdata/points_sparse_indices.gltf,testdata/skinned_triangle_high_indices.gltf,testdata/morph_triangle_high_indices.gltf.Does not overlap with #1247 or #1262.