]> OCCT Git - occt.git/commitdiff
0032181: Modeling Algorithms - ChFi3d missing error checking
authorChris Hennes (chennes) <chennes@gmail.com>
Sat, 27 Feb 2021 17:58:50 +0000 (11:58 -0600)
committerbugmaster <bugmaster@opencascade.com>
Thu, 4 Mar 2021 16:42:05 +0000 (19:42 +0300)
Throughout the ChFi3d fillet creation functions there are two sets of unchecked
errors that can result in segmentation faults when geometry-creation problems
occur.

The first is that the functions ChFi3d_cherche_* may fail to find the requested
item: they silently return without setting the required reference, which is
then accessed by the algorithms. This can be caught with a conditional at the
end of the function that throws an exception if the required item was not
found.

The second class of unchecked error is the use of BRep_Tool::CurveOnSurface,
which may fail to create the required curve, returning a null handle. In many
cases in the existing fillet code this is not checked. This can be dealt with
by checking the returned handle using IsNull() and throwing an exception
if the call did not result in valid geometry.

src/ChFi3d/ChFi3d_Builder_0.cxx
src/ChFi3d/ChFi3d_Builder_C1.cxx
src/ChFi3d/ChFi3d_Builder_CnCrn.cxx

index 89bb505133f4458069adb2adf6c39fd276b44627..27ea6dd75b4101a483fc56fddb880542744dd7a3 100644 (file)
@@ -4394,6 +4394,9 @@ void ChFi3d_cherche_face1 (const TopTools_ListOfShape & map,
     if (!Fcur.IsSame(F1)) {
       F=Fcur;trouve=Standard_True;}
   }
+  if (F.IsNull()) {
+    throw Standard_ConstructionError ("Failed to find face");
+  }
 } 
 //=======================================================================
 //function : cherche_element
@@ -4433,6 +4436,9 @@ void ChFi3d_cherche_element(const TopoDS_Vertex & V,
       }
     }
   }
+  if (E.IsNull()) {
+    throw Standard_ConstructionError ("Failed to find element");
+  }
 } 
 //=======================================================================
 //function : cherche_edge
@@ -4477,6 +4483,9 @@ void ChFi3d_cherche_edge(const TopoDS_Vertex & V,
       }
     }
   }
+  if (E.IsNull()) {
+    throw Standard_ConstructionError ("Failed to find edge");
+  }
 }
 
 //=======================================================================
index c723fd6dfd419d2632aba3c97ec0761b792ded6c..9d78c539444df3dc5e353e291025b7dbc8088cea 100644 (file)
@@ -334,6 +334,8 @@ static Standard_Boolean IntersUpdateOnSame(Handle(GeomAdaptor_Surface)& HGs,
     return Standard_False;
 
   Handle(Geom2d_Curve) gpcprol = BRep_Tool::CurveOnSurface(Eprol,Fprol,uf,ul);
+  if (gpcprol.IsNull()) 
+    throw Standard_ConstructionError ("Failed to get p-curve of edge");
   Handle(Geom2dAdaptor_Curve) pcprol = new Geom2dAdaptor_Curve(gpcprol);
   Standard_Real partemp = BRep_Tool::Parameter(Vtx,Eprol);
 
@@ -634,7 +636,7 @@ void ChFi3d_Builder::PerformOneCorner(const Standard_Integer Index,
 
   if (onsame) {
     if (!CV1.IsOnArc() && !CV2.IsOnArc())
-      throw Standard_Failure("Corner OnSame : no point on arc");
+      throw Standard_ConstructionError ("Corner OnSame : no point on arc");
     else if (CV1.IsOnArc() && CV2.IsOnArc()) {
        Standard_Boolean sur1 = 0, sur2 = 0;
       for(ex.Init(CV1.Arc(),TopAbs_VERTEX); ex.More(); ex.Next()) {
@@ -818,11 +820,15 @@ void ChFi3d_Builder::PerformOneCorner(const Standard_Integer Index,
     if (onsame && IFopArc == 1) pfac1 = p2dbout;
     else {
       Hc1 = BRep_Tool::CurveOnSurface(CV1.Arc(),Fv,Ubid,Ubid);
+      if (Hc1.IsNull()) 
+        throw Standard_ConstructionError ("Failed to get p-curve of edge");
       pfac1 = Hc1->Value(CV1.ParameterOnArc());
     }
     if (onsame && IFopArc == 2) pfac2 = p2dbout;
     else {
       Hc2 = BRep_Tool::CurveOnSurface(CV2.Arc(),Fv,Ubid,Ubid);
+      if (Hc2.IsNull()) 
+        throw Standard_ConstructionError ("Failed to get p-curve of edge");
       pfac2 = Hc2->Value(CV2.ParameterOnArc());
     }
     if (Fi1.LineIndex() != 0) {
@@ -1046,6 +1052,8 @@ void ChFi3d_Builder::PerformOneCorner(const Standard_Integer Index,
         Standard_Real first, last, prm1, prm2;
         Standard_Boolean onfirst, FirstToPar;
         Handle(Geom2d_Curve) Hc = BRep_Tool::CurveOnSurface( CV[i].Arc(), Fv, first, last );
+        if (Hc.IsNull()) 
+          throw Standard_ConstructionError ("Failed to get p-curve of edge");
         pfac1 = Hc->Value( CV[i].ParameterOnArc() );
         PcF = Pc->Value( Udeb );
         PcL = Pc->Value( Ufin );
@@ -1097,6 +1105,8 @@ void ChFi3d_Builder::PerformOneCorner(const Standard_Integer Index,
         TopoDS_Edge aLocalEdge = CV[i].Arc();
         aLocalEdge.Reverse();
         Handle(Geom2d_Curve) HcR = BRep_Tool::CurveOnSurface( aLocalEdge, Fv, first, last );
+        if (HcR.IsNull()) 
+          throw Standard_ConstructionError ("Failed to get p-curve of edge");
         Interfc = ChFi3d_FilCurveInDS( indcurv, indface, HcR, aLocalEdge.Orientation() );
         DStr.ChangeShapeInterferences(indface).Append( Interfc );
         //modify degenerated edge
@@ -1122,6 +1132,8 @@ void ChFi3d_Builder::PerformOneCorner(const Standard_Integer Index,
         {
           Standard_Real fd, ld;
           Handle(Geom2d_Curve) Cd = BRep_Tool::CurveOnSurface( Edeg, Fv, fd, ld );
+          if (Cd.IsNull()) 
+            throw Standard_ConstructionError ("Failed to get p-curve of edge");
           Handle(Geom2d_TrimmedCurve) tCd = Handle(Geom2d_TrimmedCurve)::DownCast(Cd);
           if (! tCd.IsNull())
             Cd = tCd->BasisCurve();
@@ -1240,9 +1252,13 @@ void ChFi3d_Builder::PerformOneCorner(const Standard_Integer Index,
     const ChFiDS_FaceInterference& Fiop = Fd->Interference(IFopArc);
     gp_Pnt2d pop1, pop2, pv1, pv2;
     Hc = BRep_Tool::CurveOnSurface(Arcprol,Fop,Ubid,Ubid);
+    if (Hc.IsNull()) 
+      throw Standard_ConstructionError ("Failed to get p-curve of edge");
     pop1 = Hc->Value(parVtx);
     pop2 = Fiop.PCurveOnFace()->Value(Fiop.Parameter(isfirst));
     Hc = BRep_Tool::CurveOnSurface(Arcprol,Fv,Ubid,Ubid);
+    if (Hc.IsNull()) 
+      throw Standard_ConstructionError ("Failed to get p-curve of edge");
     pv1 = Hc->Value(parVtx);
     pv2 = p2dbout;
     ChFi3d_Recale(Bs,pv1,pv2,1);
@@ -1432,6 +1448,9 @@ static void cherche_face (const TopTools_ListOfShape & map,
       }
     }
   }
+  if (F.IsNull()) {
+    throw Standard_ConstructionError ("Failed to find face.");
+  }
 }
 
 //=======================================================================
@@ -1462,6 +1481,9 @@ static void cherche_edge1 (const TopoDS_Face & F1,
                {Edge=Ecur1;trouve=Standard_True;}
             }
       }
+  if (Edge.IsNull()) {
+    throw Standard_ConstructionError ("Failed to find edge.");
+  }
 }
 
 //=======================================================================
@@ -2339,7 +2361,11 @@ void ChFi3d_Builder::PerformIntersectionAtEnd(const Standard_Integer Index)
          paredge2=inters.Point(nbp).W();
          if (!extend) {
            cfacemoins1=BRep_Tool::CurveOnSurface(E2,F,u2,v2);
+            if (cfacemoins1.IsNull()) 
+              throw Standard_ConstructionError ("Failed to get p-curve of edge");
            cface=BRep_Tool::CurveOnSurface(E2,Face[nb],u2,v2);
+            if (cface.IsNull()) 
+              throw Standard_ConstructionError ("Failed to get p-curve of edge");
            cfacemoins1->D0(paredge2,pfac2);
            cface->D0(paredge2,pint);
          }
@@ -3971,6 +3997,8 @@ void ChFi3d_Builder::IntersectMoreCorner(const Standard_Integer Index)
       // Arcprol is an edge of tangency, ultimate adjustment by an extrema curve/curve is attempted.
       Standard_Real ff,ll;
       Handle(Geom2d_Curve) gpcprol = BRep_Tool::CurveOnSurface(Arcprol,Fv,ff,ll);
+      if (gpcprol.IsNull()) 
+        throw Standard_ConstructionError ("Failed to get p-curve of edge");
       Handle(Geom2dAdaptor_Curve) pcprol = new Geom2dAdaptor_Curve(gpcprol);
       Standard_Real partemp = BRep_Tool::Parameter(Vtx,Arcprol);
       inters = Update(HBs,pcprol,HGs,FiopArc,CPopArc,p2dbout,
@@ -4005,11 +4033,15 @@ void ChFi3d_Builder::IntersectMoreCorner(const Standard_Integer Index)
     if( IFopArc == 1) pfac1 = p2dbout;
     else {
       Hc1 = BRep_Tool::CurveOnSurface(CV1.Arc(),Fv,Ubid,Ubid);
+      if (Hc1.IsNull()) 
+        throw Standard_ConstructionError ("Failed to get p-curve of edge");
       pfac1 = Hc1->Value(CV1.ParameterOnArc());
     }
     if(IFopArc == 2) pfac2 = p2dbout;
     else {
       Hc2 = BRep_Tool::CurveOnSurface(CV2.Arc(),Fv,Ubid,Ubid);
+      if (Hc2.IsNull()) 
+        throw Standard_ConstructionError ("Failed to get p-curve of edge");
       pfac2 = Hc2->Value(CV2.ParameterOnArc());
     }
     if(Fi1.LineIndex() != 0){
@@ -4279,9 +4311,13 @@ void ChFi3d_Builder::IntersectMoreCorner(const Standard_Integer Index)
 //  Modified by skv - Thu Aug 21 11:55:58 2008 OCC20222 End
     //fin modif
     Hc = BRep_Tool::CurveOnSurface(Arcprolbis,Fop,Ubid,Ubid);
+    if (Hc.IsNull()) 
+      throw Standard_ConstructionError ("Failed to get p-curve of edge");
     pop1 = Hc->Value(parVtx);
     pop2 = Fiop.PCurveOnFace()->Value(Fiop.Parameter(isfirst));
     Hc = BRep_Tool::CurveOnSurface(Arcprol,Fv,Ubid,Ubid);
+    if (Hc.IsNull()) 
+      throw Standard_ConstructionError ("Failed to get p-curve of edge");
     //modif
     parVtx = BRep_Tool::Parameter(Vtx,Arcprol);
     //fin modif
index 2bf88ee47cbae18b4cf127820d982863b433a140..10239c91d38faf670f6b8f4c2eb34ae5a56b805a 100644 (file)
@@ -290,6 +290,9 @@ static void cherche_edge1 (const TopoDS_Face & F1,
       {Edge=Ecur1;trouve=Standard_True;}
     }
   }
+  if (Edge.IsNull()) {
+    throw Standard_ConstructionError ("Failed to find edge");
+  }
 }
 
 //=======================================================================
@@ -348,6 +351,10 @@ static void CurveHermite (const TopOpeBRepDS_DataStructure& DStr,
     else  ilin=CDicplus->SetOfSurfData()->Value(icplus)->InterferenceOnS2().LineIndex();
     c2=DStr.Curve(ilin ).Curve();
   }
+  if (c1.IsNull()) 
+    throw Standard_ConstructionError ("Failed to get 3D curve of edge");
+  if (c2.IsNull()) 
+    throw Standard_ConstructionError ("Failed to get 3D curve of edge");
   c1->D1(picmoins,p01,d11);
   c2->D1(picplus,p02,d12);
   Standard_Integer size = 4;
@@ -413,8 +420,12 @@ static void CurveHermite (const TopOpeBRepDS_DataStructure& DStr,
             }
             Eproj.Append(E1);
             proj1=BRep_Tool::CurveOnSurface(E1,F,up1,up2);
+            if (proj1.IsNull()) 
+              throw Standard_ConstructionError ("Failed to get p-curve of edge");
             proj2d.Append(new Geom2d_TrimmedCurve(proj1,up1,up2));
             proj1c=BRep_Tool::Curve(E1,up1,up2);
+            if (proj1c.IsNull()) 
+              throw Standard_ConstructionError ("Failed to get 3D curve of edge");
             cproj.Append(new Geom_TrimmedCurve(proj1c,up1,up2));
             if (error>BRep_Tool::Tolerance(E1)) error=BRep_Tool::Tolerance(E1);
           }
@@ -1138,7 +1149,8 @@ void  ChFi3d_Builder::PerformMoreThreeCorner(const Standard_Integer Jndex,
       nbcouture++;
     }
     else ChFi3d_cherche_edge(V1,Evive,Fcur,Enext,VV);
-    if (Enext.IsNull())throw Standard_Failure("PerformMoreThreeCorner: pb in the parsing of edges and faces");
+    if (Enext.IsNull())
+      throw Standard_ConstructionError ("PerformMoreThreeCorner: pb in the parsing of edges and faces");
     if (Enext.IsSame(edgelibre1)|| Enext.IsSame(edgelibre2)) {
       CD.SetValue(ii, cdbid);
       Index.SetValue(ii, 0);
@@ -2226,6 +2238,9 @@ void  ChFi3d_Builder::PerformMoreThreeCorner(const Standard_Integer Jndex,
                                               u1bid,u2bid);
        else
          Calcul_C2dOnFace(CD.Value(ic),jf.Value(ic),i.Value(ic,icplus),curv2d1);
+
+        if (curv2d1.IsNull()) 
+          throw Standard_ConstructionError ("Failed to get p-curve of edge");
        p2d1 = curv2d1 ->Value(p.Value(ic,icplus));
        
        // recuperation de la deuxieme courbe 2d
@@ -2237,6 +2252,8 @@ void  ChFi3d_Builder::PerformMoreThreeCorner(const Standard_Integer Jndex,
          jfp = 3 - jf.Value(icplus);
          Calcul_C2dOnFace(CD.Value(icplus),jfp,i.Value(icplus,ic),curv2d2);
        }
+        if (curv2d2.IsNull()) 
+          throw Standard_ConstructionError ("Failed to get p-curve of edge");
        p2d2 = curv2d2 ->Value(p.Value(icplus,ic));
 
        Asurf = new GeomAdaptor_Surface(BRep_Tool::Surface(TopoDS::Face(Fvive.Value(ic,icplus))));
@@ -2465,8 +2482,12 @@ void  ChFi3d_Builder::PerformMoreThreeCorner(const Standard_Integer Jndex,
          n3d++;
          proj=BRep_Tool::CurveOnSurface(TopoDS::Edge(Eproj.Value(nb)),
                                         TopoDS::Face(Fproj.Value(nb)),up1,up2);
+          if (proj.IsNull()) 
+            throw Standard_ConstructionError ("Failed to get p-curve of edge");
          proj2d=new Geom2d_TrimmedCurve(proj,up1,up2);
          projc=BRep_Tool::Curve(TopoDS::Edge(Eproj.Value(nb)),up1,up2);
+          if (projc.IsNull()) 
+            throw Standard_ConstructionError ("Failed to get 3D curve of edge");
          cproj=new Geom_TrimmedCurve(projc,up1,up2);
          pardeb=cproj->FirstParameter();
          parfin=cproj->LastParameter();