Skip to content

Fix missing return in SceneUtils::InstantiateMesh error path - #1217

Draft
rootkiller6788 wants to merge 1 commit into
google:mainfrom
rootkiller6788:fix-instantiate-mesh-missing-return
Draft

Fix missing return in SceneUtils::InstantiateMesh error path#1217
rootkiller6788 wants to merge 1 commit into
google:mainfrom
rootkiller6788:fix-instantiate-mesh-missing-return

Conversation

@rootkiller6788

Copy link
Copy Markdown

Summary

SceneUtils::InstantiateMesh checks that the scene has a base mesh matching the requested instance.mesh_index, but the constructed error Status was never returned:

if (scene.NumMeshes() <= instance.mesh_index.value()) {
  Status(Status::DRACO_ERROR, "Scene has no corresponding base mesh.");  // discarded
}

The bounds check was therefore a no-op and execution continued to scene.GetMesh(instance.mesh_index), which performs an unchecked meshes_[index] access and crashes on an out-of-range index.

This fix returns the error status as the surrounding code clearly intends, and adds a regression test that instantiates a mesh with an index not present in the scene.

Verification

Built draco_tests (MinGW, DRACO_TRANSCODER_SUPPORTED=ON):

  • Without the fix, the new SceneUtilsTest.TestInstantiateMeshWithInvalidMeshIndex test segfaults (exit code 139) due to the out-of-bounds access.
  • With the fix, the test passes and InstantiateMesh returns an error status.

The existing TestInstantiateMesh and TestInstantiateMeshWithIdentityTransformation tests are unaffected.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant