From cca36b6b2188e588954ffdbb5a04687af5662f23 Mon Sep 17 00:00:00 2001 From: emv Date: Mon, 13 May 2019 12:32:09 +0300 Subject: [PATCH] 0030708: Modeling Data - Exception is raised while initializing TopoDS_Iterator with null shape Added protection from null shapes to TopoDS_Iterator::Initialize method. --- src/QABugs/QABugs_20.cxx | 53 +++++++++++++++++++++++++++++++++ src/TopoDS/TopoDS_Iterator.cxx | 11 +++---- tests/bugs/moddata_3/bug30708_1 | 10 +++++++ tests/bugs/moddata_3/bug30708_2 | 10 +++++++ 4 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 tests/bugs/moddata_3/bug30708_1 create mode 100644 tests/bugs/moddata_3/bug30708_2 diff --git a/src/QABugs/QABugs_20.cxx b/src/QABugs/QABugs_20.cxx index 09653f6e70..7b676e5e84 100644 --- a/src/QABugs/QABugs_20.cxx +++ b/src/QABugs/QABugs_20.cxx @@ -3223,6 +3223,53 @@ static Standard_Integer OCC30435(Draw_Interpretor& di, Standard_Integer, const c } +//======================================================================= +//function : OCC30708_1 +//purpose : Tests initialization of the TopoDS_Iterator with null shape +//======================================================================= +static Standard_Integer OCC30708_1 (Draw_Interpretor& di, Standard_Integer, const char**) +{ + TopoDS_Iterator it; + try + { + OCC_CATCH_SIGNALS + + TopoDS_Shape empty; + it.Initialize (empty); + + } + catch (Standard_Failure) + { + di << "Cannot initialize TopoDS_Iterator with null shape\n"; + return 0; + } + + if (it.More()) + di << "Incorrect Iterator initialization: method More() returns true on null shape\n"; + + return 0; +} + +//======================================================================= +//function : OCC30708_2 +//purpose : Tests initialization of the BRepLib_MakeWire with null wire +//======================================================================= +static Standard_Integer OCC30708_2 (Draw_Interpretor& di, Standard_Integer, const char**) +{ + try + { + OCC_CATCH_SIGNALS + + TopoDS_Wire empty; + BRepLib_MakeWire aWBuilder (empty); + } + catch (Standard_Failure) + { + di << "Cannot initialize BRepLib_MakeWire with null wire\n"; + } + + return 0; +} void QABugs::Commands_20(Draw_Interpretor& theCommands) { const char *group = "QABugs"; @@ -3274,5 +3321,11 @@ void QABugs::Commands_20(Draw_Interpretor& theCommands) { "QAEndsWith string endstring", __FILE__, QAEndsWith, group); + theCommands.Add ("OCC30708_1", "Tests initialization of the TopoDS_Iterator with null shape", + __FILE__, OCC30708_1, group); + + theCommands.Add ("OCC30708_2", "Tests initialization of the BRepLib_MakeWire with null shape", + __FILE__, OCC30708_2, group); + return; } diff --git a/src/TopoDS/TopoDS_Iterator.cxx b/src/TopoDS/TopoDS_Iterator.cxx index ce993b318a..eb5aab9010 100644 --- a/src/TopoDS/TopoDS_Iterator.cxx +++ b/src/TopoDS/TopoDS_Iterator.cxx @@ -38,13 +38,16 @@ void TopoDS_Iterator::Initialize(const TopoDS_Shape& S, myOrientation = S.Orientation(); else myOrientation = TopAbs_FORWARD; - myShapes.Initialize(S.TShape()->myShapes); + + if (S.IsNull()) + myShapes = TopoDS_ListIteratorOfListOfShape(); + else + myShapes.Initialize(S.TShape()->myShapes); + if (More()) { myShape = myShapes.Value(); myShape.Orientation(TopAbs::Compose(myOrientation,myShape.Orientation())); - //modified by NIZNHY-PKV Fri Jan 16 07:42:30 2009f if (!myLocation.IsIdentity()) - //modified by NIZNHY-PKV Fri Jan 16 07:42:37 2009t myShape.Move(myLocation); } } @@ -60,9 +63,7 @@ void TopoDS_Iterator::Next() if (More()) { myShape = myShapes.Value(); myShape.Orientation(TopAbs::Compose(myOrientation,myShape.Orientation())); - //modified by NIZNHY-PKV Fri Jan 16 07:42:30 2009f if (!myLocation.IsIdentity()) - //modified by NIZNHY-PKV Fri Jan 16 07:42:37 2009t myShape.Move(myLocation); } } diff --git a/tests/bugs/moddata_3/bug30708_1 b/tests/bugs/moddata_3/bug30708_1 new file mode 100644 index 0000000000..cd6149a528 --- /dev/null +++ b/tests/bugs/moddata_3/bug30708_1 @@ -0,0 +1,10 @@ +puts "================" +puts "0030708: Modeling Data - Crash while initializing TopoDS_Iterator with null shape" +puts "================" +puts "" + +pload QAcommands + +if { [regexp "Cannot initialize" [OCC30708_1]]} { + puts "Error: Cannot initialize TopoDS_Iterator with null shape" +} diff --git a/tests/bugs/moddata_3/bug30708_2 b/tests/bugs/moddata_3/bug30708_2 new file mode 100644 index 0000000000..4acb278cc6 --- /dev/null +++ b/tests/bugs/moddata_3/bug30708_2 @@ -0,0 +1,10 @@ +puts "================" +puts "0030708: Modeling Data - Crash while initializing TopoDS_Iterator with null shape" +puts "================" +puts "" + +pload QAcommands + +if { [regexp "Cannot initialize" [OCC30708_2]]} { + puts "Error: Cannot initialize BRepLib_MakeWire with null wire" +}