0030616: Crash on reading STEP file
authorgka <gka@opencascade.com>
Thu, 28 Mar 2019 15:25:20 +0000 (18:25 +0300)
committerapn <apn@opencascade.com>
Tue, 2 Apr 2019 18:24:57 +0000 (21:24 +0300)
Added protections to avoid exceptions for null objects.
For reading entity StepShape_ToleranceValue was added reading lower and upper bounds represented by entities "StepRepr_ReprItemAndMeasureWithUnit" or "StepRepr_MeasureRepresentationItem"

src/RWStepShape/RWStepShape_RWToleranceValue.cxx
src/STEPCAFControl/STEPCAFControl_Reader.cxx
src/StepShape/StepShape_ToleranceValue.cxx
src/StepShape/StepShape_ToleranceValue.hxx
tests/bugs/step/bug30616 [new file with mode: 0644]

index 66cd8fc..f2821fa 100644 (file)
@@ -19,6 +19,8 @@
 #include <StepData_StepReaderData.hxx>
 #include <StepData_StepWriter.hxx>
 #include <StepShape_ToleranceValue.hxx>
+#include <StepRepr_MeasureRepresentationItem.hxx>
+#include <StepRepr_ReprItemAndMeasureWithUnit.hxx>
 
 RWStepShape_RWToleranceValue::RWStepShape_RWToleranceValue () {}
 
@@ -34,18 +36,45 @@ void RWStepShape_RWToleranceValue::ReadStep
 
        // --- own field : lower_bound ---
 
-       Handle(StepBasic_MeasureWithUnit) LB;
-       data->ReadEntity (num,1,"lower_bound",ach,
-                         STANDARD_TYPE(StepBasic_MeasureWithUnit),LB);
+       Handle(Standard_Transient) LB;
+       if(!data->ReadEntity (num,1,"lower_bound",ach,
+                         STANDARD_TYPE(StepBasic_MeasureWithUnit),LB))
+  {
+    Handle(StepRepr_MeasureRepresentationItem) aMSR;
+    Handle(StepRepr_ReprItemAndMeasureWithUnit) aRIMU;
+     
+    if(data->ReadEntity (num,1,"lower_bound",ach,
+                         STANDARD_TYPE(StepRepr_MeasureRepresentationItem),aMSR) || 
+      data->ReadEntity (num,1,"lower_bound",ach,STANDARD_TYPE(StepRepr_ReprItemAndMeasureWithUnit), aRIMU))
+    {
+      if(!aMSR.IsNull())
+        LB = aMSR;
+       else if(!aRIMU.IsNull())
+        LB = aRIMU;
+    }
+  }
 
        // --- own field : upper_bound ---
 
-       Handle(StepBasic_MeasureWithUnit) UB;
-       data->ReadEntity (num,2,"upper_bound",ach,
-                         STANDARD_TYPE(StepBasic_MeasureWithUnit),UB);
+       Handle(Standard_Transient) UB;
+       if(!data->ReadEntity (num,2,"upper_bound",ach,
+                         STANDARD_TYPE(StepBasic_MeasureWithUnit),UB))
+  {
+     Handle(StepRepr_MeasureRepresentationItem) aMSR1;
+     Handle(StepRepr_ReprItemAndMeasureWithUnit) aRIMU1;
+    if(data->ReadEntity (num,2,"upper_bound",ach,STANDARD_TYPE(StepRepr_MeasureRepresentationItem),aMSR1) || 
+      data->ReadEntity (num,2,"upper_bound",ach,STANDARD_TYPE(StepRepr_ReprItemAndMeasureWithUnit), aRIMU1))
+    {
+      if(!aMSR1.IsNull())
+        UB = aMSR1;
+      else if(!aRIMU1.IsNull())
+        UB = aRIMU1;
+    }
+  }
 
        //--- Initialisation of the read entity ---
-
+  if( !LB.IsNull() && !UB.IsNull())
+    ach->ClearFails();
        ent->Init(LB,UB);
 }
 
index afeae40..49c0472 100644 (file)
@@ -3239,9 +3239,23 @@ static void setDimObjectToXCAF(const Handle(Standard_Transient)& theEnt,
         aTV = aTMD.ToleranceValue();
         if (aTV.IsNull()) continue;
 
-        Handle(StepBasic_MeasureWithUnit) aMWU = aTV->UpperBound();
-        Standard_Real aVal = aTV->UpperBound()->ValueComponent();
-        StepBasic_Unit anUnit = aTV->UpperBound()->UnitComponent();
+        Handle(Standard_Transient) aUpperBound = aTV->UpperBound();
+        if(aUpperBound.IsNull())
+          continue;
+        Handle(StepBasic_MeasureWithUnit) aMWU;
+        if(aUpperBound->IsKind(STANDARD_TYPE(StepBasic_MeasureWithUnit)) )
+          aMWU = Handle(StepBasic_MeasureWithUnit)::DownCast(aUpperBound);
+        else if(aUpperBound->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndMeasureWithUnit)) )
+        {
+          Handle(StepRepr_ReprItemAndMeasureWithUnit) aReprMeasureItem = 
+            Handle(StepRepr_ReprItemAndMeasureWithUnit)::DownCast(aUpperBound);
+          aMWU = aReprMeasureItem->GetMeasureWithUnit();
+
+        }
+        if(aMWU.IsNull())
+          continue;
+        Standard_Real aVal = aMWU->ValueComponent();
+        StepBasic_Unit anUnit = aMWU->UnitComponent();
         if (anUnit.IsNull()) continue;
         if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue;
         Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
@@ -3259,9 +3273,25 @@ static void setDimObjectToXCAF(const Handle(Standard_Transient)& theEnt,
         }
         aDim3 = aVal;
 
-        aMWU = aTV->LowerBound();
-        aVal = aTV->LowerBound()->ValueComponent();
-        anUnit = aTV->LowerBound()->UnitComponent();
+        
+        Handle(Standard_Transient) aLowerBound = aTV->LowerBound();
+        if(aLowerBound.IsNull())
+          continue;
+       
+        if(aLowerBound->IsKind(STANDARD_TYPE(StepBasic_MeasureWithUnit)) )
+          aMWU = Handle(StepBasic_MeasureWithUnit)::DownCast(aLowerBound);
+        else if(aLowerBound->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndMeasureWithUnit)) )
+        {
+          Handle(StepRepr_ReprItemAndMeasureWithUnit) aReprMeasureItem = 
+            Handle(StepRepr_ReprItemAndMeasureWithUnit)::DownCast(aLowerBound);
+          aMWU = aReprMeasureItem->GetMeasureWithUnit();
+
+        }
+        if(aMWU.IsNull())
+          continue;
+      
+        aVal = aMWU->ValueComponent();
+        anUnit = aMWU->UnitComponent();
         if (anUnit.IsNull()) continue;
         if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue;
         NU = anUnit.NamedUnit();
@@ -4105,7 +4135,7 @@ void collectViewShapes(const Handle(XSControl_WorkSession)& theWS,
     if (!anIter.Value()->IsKind(STANDARD_TYPE(StepRepr_RepresentationRelationship)))
       continue;
     Handle(StepRepr_RepresentationRelationship) aReprRelationship = Handle(StepRepr_RepresentationRelationship)::DownCast(anIter.Value());
-    if (aReprRelationship->Rep1() != theRepr)
+    if (!aReprRelationship->Rep1().IsNull() && aReprRelationship->Rep1() != theRepr)
       collectViewShapes(theWS, theDoc, aReprRelationship->Rep1(), theShapes);
   }
 }
index e5c5e2f..dee367d 100644 (file)
@@ -21,21 +21,21 @@ IMPLEMENT_STANDARD_RTTIEXT(StepShape_ToleranceValue,Standard_Transient)
 StepShape_ToleranceValue::StepShape_ToleranceValue  ()    {  }
 
 void  StepShape_ToleranceValue::Init
-  (const Handle(StepBasic_MeasureWithUnit)& lower_bound,
-   const Handle(StepBasic_MeasureWithUnit)& upper_bound)
+  (const Handle(Standard_Transient)& lower_bound,
+   const Handle(Standard_Transient)& upper_bound)
 {
   theLowerBound = lower_bound;
   theUpperBound = upper_bound;
 }
 
-Handle(StepBasic_MeasureWithUnit)  StepShape_ToleranceValue::LowerBound () const
+Handle(Standard_Transient)  StepShape_ToleranceValue::LowerBound () const
 {  return theLowerBound;  }
 
-void  StepShape_ToleranceValue::SetLowerBound (const Handle(StepBasic_MeasureWithUnit)& lower_bound)
+void  StepShape_ToleranceValue::SetLowerBound (const Handle(Standard_Transient)& lower_bound)
 {  theLowerBound = lower_bound;  }
 
-Handle(StepBasic_MeasureWithUnit)  StepShape_ToleranceValue::UpperBound () const
+Handle(Standard_Transient)  StepShape_ToleranceValue::UpperBound () const
 {  return theUpperBound;  }
 
-void  StepShape_ToleranceValue::SetUpperBound (const Handle(StepBasic_MeasureWithUnit)& upper_bound)
+void  StepShape_ToleranceValue::SetUpperBound (const Handle(Standard_Transient)& upper_bound)
 {  theUpperBound = upper_bound;  }
index 9fe6bc9..b911838 100644 (file)
@@ -35,15 +35,15 @@ public:
   
   Standard_EXPORT StepShape_ToleranceValue();
   
-  Standard_EXPORT void Init (const Handle(StepBasic_MeasureWithUnit)& lower_bound, const Handle(StepBasic_MeasureWithUnit)& upper_bound);
+  Standard_EXPORT void Init (const Handle(Standard_Transient)& lower_bound, const Handle(Standard_Transient)& upper_bound);
   
-  Standard_EXPORT Handle(StepBasic_MeasureWithUnit) LowerBound() const;
+  Standard_EXPORT Handle(Standard_Transient) LowerBound() const;
   
-  Standard_EXPORT void SetLowerBound (const Handle(StepBasic_MeasureWithUnit)& lower_bound);
+  Standard_EXPORT void SetLowerBound (const Handle(Standard_Transient)& lower_bound);
   
-  Standard_EXPORT Handle(StepBasic_MeasureWithUnit) UpperBound() const;
+  Standard_EXPORT Handle(Standard_Transient) UpperBound() const;
   
-  Standard_EXPORT void SetUpperBound (const Handle(StepBasic_MeasureWithUnit)& upper_bound);
+  Standard_EXPORT void SetUpperBound (const Handle(Standard_Transient)& upper_bound);
 
 
 
@@ -58,8 +58,8 @@ protected:
 private:
 
 
-  Handle(StepBasic_MeasureWithUnit) theLowerBound;
-  Handle(StepBasic_MeasureWithUnit) theUpperBound;
+  Handle(Standard_Transient) theLowerBound;
+  Handle(Standard_Transient) theUpperBound;
 
 
 };
diff --git a/tests/bugs/step/bug30616 b/tests/bugs/step/bug30616
new file mode 100644 (file)
index 0000000..ec76d95
--- /dev/null
@@ -0,0 +1,8 @@
+puts "===================================="
+puts "0030616: Crash on reading STEP file"
+puts "===================================="
+puts ""
+
+param xstep.cascade.unit M
+
+ReadStep D [locate_data_file bug30616_nist_ctc_01_asme1_ap242.stp]