From 8f48c3fce3c874c3c2f27bdebc1d33a233cd62f5 Mon Sep 17 00:00:00 2001 From: rootkiller6788 Date: Fri, 21 Aug 2026 16:50:36 +0800 Subject: [PATCH] Fix missing return in SceneUtils::InstantiateMesh error path The bounds check for the mesh index constructed a Status object but never returned it, so an invalid mesh index fell through to an out-of-bounds access of the scene's mesh vector. Return the error status and add a regression test that instantiates a mesh with an index not present in the scene. --- src/draco/scene/scene_utils.cc | 2 +- src/draco/scene/scene_utils_test.cc | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/draco/scene/scene_utils.cc b/src/draco/scene/scene_utils.cc index e43753e78..31f70896d 100644 --- a/src/draco/scene/scene_utils.cc +++ b/src/draco/scene/scene_utils.cc @@ -457,7 +457,7 @@ StatusOr> SceneUtils::InstantiateMesh( const Scene &scene, const MeshInstance &instance) { // Check if the |scene| has base mesh corresponding to mesh |instance|. if (scene.NumMeshes() <= instance.mesh_index.value()) { - Status(Status::DRACO_ERROR, "Scene has no corresponding base mesh."); + return Status(Status::DRACO_ERROR, "Scene has no corresponding base mesh."); } // Check that mesh has valid positions. diff --git a/src/draco/scene/scene_utils_test.cc b/src/draco/scene/scene_utils_test.cc index c3ead1db1..b0c97a1e7 100644 --- a/src/draco/scene/scene_utils_test.cc +++ b/src/draco/scene/scene_utils_test.cc @@ -529,6 +529,18 @@ TEST(SceneUtilsTest, TestInstantiateMesh) { EXPECT_NEAR(instanced_bbox.GetMaxPoint()[2], +1.05800, tolerance); } +TEST(SceneUtilsTest, TestInstantiateMeshWithInvalidMeshIndex) { + // Instantiating a mesh with an index that is not present in the scene must + // return an error instead of accessing the out-of-bounds mesh. + draco::Scene scene; + const draco::SceneUtils::MeshInstance invalid_instance = { + draco::MeshIndex(0), draco::SceneNodeIndex(0), 0, + Eigen::Matrix4d::Identity()}; + const auto result = + draco::SceneUtils::InstantiateMesh(scene, invalid_instance); + EXPECT_FALSE(result.ok()); +} + TEST(SceneUtilsTest, TestCleanupEmptyMeshGroup) { auto scene = draco::ReadSceneFromTestFile("CesiumMilkTruck/glTF/CesiumMilkTruck.gltf");