Quiet coverity by adding guard when accessing the UV primvar data 90/324490/3
authorRichard Huang <r.huang@samsung.com>
Mon, 19 May 2025 12:44:09 +0000 (13:44 +0100)
committerRichard Huang <r.huang@samsung.com>
Mon, 19 May 2025 17:12:44 +0000 (18:12 +0100)
Change-Id: I1650604cb3f78ec0274a85409361d1e4cdd14ce6

dali-usd-loader/internal/usd-loader-impl.cpp

index 5b237685531519212af2c5e3ff6768be486f0dc2..0f60138a35e1a26cdfb684bdcd74fda602f58d10 100644 (file)
@@ -422,8 +422,7 @@ void UsdLoaderImpl::Impl::GetXformableTransformation(const UsdPrim& prim, Vector
 NodeDefinition* UsdLoaderImpl::Impl::AddNodeToScene(SceneDefinition& scene, const std::string nodeName, const Index parentIndex, const Vector3& position, const Quaternion& rotation, const Vector3& scale, bool setTransformation)
 {
   // Add the node to the scene graph
-  auto weakNode = scene.AddNode([&]()
-                                {
+  auto weakNode = scene.AddNode([&]() {
         std::unique_ptr<NodeDefinition> nodeDefinition{new NodeDefinition()};
 
         nodeDefinition->mParentIdx = parentIndex;
@@ -692,11 +691,28 @@ void UsdLoaderImpl::Impl::ProcessMeshTexcoords(MeshDefinition& meshDefinition, s
         }
         else if(interpolation.GetString() == "vertex")
         {
+          bool indicesValid = true;
+
           // Handle vertex-based UVs
           for(auto x : subIndexArray)
           {
+            if(DALI_UNLIKELY(x < 0 || static_cast<size_t>(x) >= rawUVs.size()))
+            {
+              // This should never happen. The USD spec and the “indexed” primvar APIs guarantee that
+              // you will never have an index that lies outside the authored-values array.
+              indicesValid = false;
+              DALI_LOG_ERROR("Invalid UV index %d. Skipping this UV set.\n", x);
+              break;
+            }
+
             UVs.push_back(static_cast<GfVec2f>(rawUVs[x]));
           }
+
+          if(!indicesValid)
+          {
+            // Skip the current UV set
+            continue;
+          }
         }
         else
         {