From dcf0889fc264ee65fa5fef447bcbfc4a45067a11 Mon Sep 17 00:00:00 2001 From: ifv Date: Mon, 17 Sep 2018 17:13:44 +0300 Subject: [PATCH] 0030133: Modeling Data - Crash during visualization of invalid part Control of number of recursive calls is implemented to avoid stack overflow. --- src/GCPnts/GCPnts_QuasiUniformDeflection.cxx | 2 + src/GCPnts/GCPnts_QuasiUniformDeflection.pxx | 48 +++++++++++++++----- tests/bugs/moddata_3/bug30133 | 16 +++++++ 3 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 tests/bugs/moddata_3/bug30133 diff --git a/src/GCPnts/GCPnts_QuasiUniformDeflection.cxx b/src/GCPnts/GCPnts_QuasiUniformDeflection.cxx index b4dea426b2..bb10c57525 100644 --- a/src/GCPnts/GCPnts_QuasiUniformDeflection.cxx +++ b/src/GCPnts/GCPnts_QuasiUniformDeflection.cxx @@ -26,6 +26,8 @@ #include #include +static const Standard_Integer MyMaxQuasiFleshe = 2000; + // mask the return of a Adaptor2d_Curve2d as a gp_Pnt static gp_Pnt Value(const Adaptor3d_Curve & C, const Standard_Real Parameter) diff --git a/src/GCPnts/GCPnts_QuasiUniformDeflection.pxx b/src/GCPnts/GCPnts_QuasiUniformDeflection.pxx index 72e3fbcc35..91ee68b511 100644 --- a/src/GCPnts/GCPnts_QuasiUniformDeflection.pxx +++ b/src/GCPnts/GCPnts_QuasiUniformDeflection.pxx @@ -25,6 +25,7 @@ #include #include + static void QuasiFleche(const TheCurve&, const Standard_Real, const Standard_Real, @@ -36,7 +37,8 @@ static void QuasiFleche(const TheCurve&, const Standard_Integer, const Standard_Real, TColStd_SequenceOfReal&, - TColgp_SequenceOfPnt&); + TColgp_SequenceOfPnt&, + Standard_Integer&); static void QuasiFleche(const TheCurve&, const Standard_Real, @@ -46,7 +48,8 @@ static void QuasiFleche(const TheCurve&, const gp_Pnt&, const Standard_Integer, TColStd_SequenceOfReal&, - TColgp_SequenceOfPnt&); + TColgp_SequenceOfPnt&, + Standard_Integer&); //======================================================================= @@ -145,6 +148,7 @@ static Standard_Boolean PerformCurve (TColStd_SequenceOfReal& Parameters, const GeomAbs_Shape Continuity) { Standard_Integer Nbmin = 2; + Standard_Integer aNbCallQF = 0; gp_Pnt Pdeb; if (Continuity <= GeomAbs_G1) @@ -159,7 +163,7 @@ static Standard_Boolean PerformCurve (TColStd_SequenceOfReal& Parameters, U1, Pdeb, U2, Pfin, Nbmin, - Parameters, Points); + Parameters, Points, aNbCallQF); } else { @@ -178,7 +182,7 @@ static Standard_Boolean PerformCurve (TColStd_SequenceOfReal& Parameters, Dfin, Nbmin, EPSILON * EPSILON, - Parameters, Points); + Parameters, Points, aNbCallQF); } // cout << "Nb de pts: " << Points.Length()<< endl; return Standard_True; @@ -338,9 +342,19 @@ void QuasiFleche (const TheCurve& C, const Standard_Integer Nbmin, const Standard_Real Eps, TColStd_SequenceOfReal& Parameters, - TColgp_SequenceOfPnt& Points) + TColgp_SequenceOfPnt& Points, + Standard_Integer& theNbCalls) { + theNbCalls++; + if (theNbCalls >= MyMaxQuasiFleshe) + { + return; + } Standard_Integer Ptslength = Points.Length(); + if (theNbCalls > 100 && Ptslength < 2) + { + return; + } Standard_Real Udelta = Ufin - Udeb; gp_Pnt Pdelta; gp_Vec Vdelta; @@ -393,7 +407,7 @@ void QuasiFleche (const TheCurve& C, Vdelta, 3, Eps, - Parameters, Points); + Parameters, Points, theNbCalls); } if (Nbmin > 2) @@ -404,8 +418,9 @@ void QuasiFleche (const TheCurve& C, Vfin, Nbmin - (Points.Length() - Ptslength), Eps, - Parameters, Points); + Parameters, Points, theNbCalls); } + theNbCalls--; } @@ -421,9 +436,19 @@ void QuasiFleche (const TheCurve& C, const gp_Pnt& Pfin, const Standard_Integer Nbmin, TColStd_SequenceOfReal& Parameters, - TColgp_SequenceOfPnt& Points) + TColgp_SequenceOfPnt& Points, + Standard_Integer& theNbCalls) { + theNbCalls++; + if (theNbCalls >= MyMaxQuasiFleshe) + { + return; + } Standard_Integer Ptslength = Points.Length(); + if (theNbCalls > 100 && Ptslength < 2) + { + return; + } Standard_Real Udelta = Ufin - Udeb; gp_Pnt Pdelta; if (Nbmin > 2) @@ -450,12 +475,12 @@ void QuasiFleche (const TheCurve& C, QuasiFleche (C, Deflection2, Udeb, Pdeb, Udeb + Udelta * 0.5, Pverif, 2, - Parameters, Points); + Parameters, Points, theNbCalls); QuasiFleche (C, Deflection2, Udeb + Udelta * 0.5, Pverif, Udeb + Udelta, Pdelta, 2, - Parameters, Points); + Parameters, Points, theNbCalls); } if (Nbmin > 2) @@ -463,6 +488,7 @@ void QuasiFleche (const TheCurve& C, QuasiFleche (C, Deflection2, Udeb + Udelta, Pdelta, Ufin, Pfin, Nbmin - (Points.Length() - Ptslength), - Parameters, Points); + Parameters, Points, theNbCalls); } + theNbCalls--; } diff --git a/tests/bugs/moddata_3/bug30133 b/tests/bugs/moddata_3/bug30133 new file mode 100644 index 0000000000..8ef65ed4a8 --- /dev/null +++ b/tests/bugs/moddata_3/bug30133 @@ -0,0 +1,16 @@ +puts "================" +puts "OCC30133" +puts "================" +puts "" +########################################## +# Modeling Data - Crash during visualization of invalid part +########################################## + +restore [locate_data_file bug30133.brep] s + +vinit +vdisplay s +vfit +puts "bug30131 is OK" + +checkview -screenshot -3d -path ${imagedir}/${test_image}.png \ No newline at end of file