0028147: Data Exchange - NULL dereference while reading color from STEP file
authorkgv <kgv@opencascade.com>
Wed, 23 Nov 2016 12:53:48 +0000 (15:53 +0300)
committerapn <apn@opencascade.com>
Wed, 23 Nov 2016 12:54:55 +0000 (15:54 +0300)
StepVisual_StyledItem::Item() now does not call IsKind() on NULL object.
Add several checks for NULL to import/export.

Add test case bugs/step/bug28147

src/STEPCAFControl/STEPCAFControl_Reader.cxx
src/STEPCAFControl/STEPCAFControl_Writer.cxx
src/StepVisual/StepVisual_StyledItem.cxx
tests/bugs/step/bug28147 [new file with mode: 0644]

index 1a22acf..7231daa 100644 (file)
@@ -955,6 +955,8 @@ Standard_Boolean STEPCAFControl_Reader::ReadColors (const Handle(XSControl_WorkS
           
           Handle(StepRepr_AssemblyComponentUsage) ACU = 
             Handle(StepRepr_AssemblyComponentUsage)::DownCast(aCharDef.ProductDefinitionRelationship());
+          if (ACU.IsNull())
+            continue;
           // PTV 10.02.2003 skip styled item that refer to SHUO
           if (ACU->IsKind(STANDARD_TYPE(StepRepr_SpecifiedHigherUsageOccurrence))) {
             isSkipSHUOstyle = Standard_True;
@@ -1775,6 +1777,8 @@ Standard_Boolean readPMIPresentation(const Handle(Standard_Transient)& thePresen
                                      Handle(TCollection_HAsciiString)& thePresentName, 
                                      Bnd_Box& theBox)
 {
+  if (thePresentEntity.IsNull())
+    return Standard_False;
   Handle(Transfer_TransientProcess) aTP = theTR->TransientProcess();
   Handle(StepVisual_AnnotationCurveOccurrence) anACO;
   NCollection_Vector<Handle(StepVisual_StyledItem)> anAnnotations;
@@ -1914,6 +1918,8 @@ Standard_Boolean readAnnotationPlane(const Handle(StepVisual_AnnotationPlane) th
     return Standard_False;
   gp_Ax2 aPlaneAxes;
   Handle(StepRepr_RepresentationItem) aPlaneItem = theAnnotationPlane->Item();
+  if (aPlaneItem.IsNull())
+    return Standard_False;
   Handle(StepGeom_Axis2Placement3d) aA2P3D;
   //retrieve axes from AnnotationPlane
   if (aPlaneItem->IsKind(STANDARD_TYPE(StepGeom_Plane))) {
@@ -1958,6 +1964,8 @@ void readAnnotation(const Handle(XSControl_TransferReader)& theTR,
   const Handle(Standard_Transient) theGDT,
   const Handle(Standard_Transient)& theDimObject)
 {
+  if (theGDT.IsNull() || theDimObject.IsNull())
+    return;
   Handle(TCollection_HAsciiString) aPresentName;
   TopoDS_Compound aResAnnotation;
   Handle(Transfer_TransientProcess) aTP = theTR->TransientProcess();
@@ -2069,6 +2077,8 @@ void readConnectionPoints(const Handle(XSControl_TransferReader)& theTR,
   const Handle(Standard_Transient) theGDT,
   const Handle(XCAFDimTolObjects_DimensionObject)& theDimObject)
 {
+  if (theGDT.IsNull() || theDimObject.IsNull())
+    return;
   Handle(Transfer_TransientProcess) aTP = theTR->TransientProcess();
   const Interface_Graph& aGraph = aTP->Graph();
 
@@ -2643,6 +2653,8 @@ static void collectShapeAspect(const Handle(StepRepr_ShapeAspect)& theSA,
                                const Handle(XSControl_WorkSession)& theWS,
                                NCollection_Sequence<Handle(StepRepr_ShapeAspect)>& theSAs)
 {
+  if (theSA.IsNull())
+    return;
   Handle(XSControl_TransferReader) aTR = theWS->TransferReader();
   Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
   const Interface_Graph& aGraph = aTP->Graph();
@@ -3490,7 +3502,7 @@ static void setDimObjectToXCAF(const Handle(Standard_Transient)& theEnt,
 static Standard_Boolean getTolType(const Handle(Standard_Transient)& theEnt,
                        XCAFDimTolObjects_GeomToleranceType& theType)
 {
-  if(!theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) 
+  if(theEnt.IsNull() || !theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) 
     return Standard_False;
   theType = XCAFDimTolObjects_GeomToleranceType_None;
   if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRef)))
index 93c8277..78bae8f 100644 (file)
@@ -2050,12 +2050,14 @@ static Standard_Boolean FindPDSforDGT(const Interface_Graph &aGraph,
                                       Handle(StepShape_AdvancedFace) &AF,
                                       Handle(StepShape_EdgeCurve) &EC)
 {
+  if (ent.IsNull())
+    return Standard_False;
   if( !ent->IsKind(STANDARD_TYPE(StepShape_EdgeCurve)) && 
       !ent->IsKind(STANDARD_TYPE(StepShape_AdvancedFace)) ) 
     return Standard_False;
 
   AF = Handle(StepShape_AdvancedFace)::DownCast(ent);
-  if( ent->IsKind(STANDARD_TYPE(StepShape_EdgeCurve)) ) {
+  if( AF.IsNull() ) {
     EC = Handle(StepShape_EdgeCurve)::DownCast(ent);
     Interface_EntityIterator subs = aGraph.Sharings(EC);
     for(subs.Start(); subs.More() && AF.IsNull(); subs.Next()) {
@@ -3969,7 +3971,8 @@ static Standard_Boolean FindPDSforRI(const Interface_Graph &aGraph,
                                      Handle(StepRepr_ProductDefinitionShape) &PDS,
                                      Handle(StepRepr_RepresentationContext) &RC)
 {
-  if(!ent->IsKind(STANDARD_TYPE(StepRepr_RepresentationItem))) return Standard_False;
+  if(ent.IsNull() || !ent->IsKind(STANDARD_TYPE(StepRepr_RepresentationItem)))
+    return Standard_False;
   Interface_EntityIterator subs = aGraph.Sharings(ent);
   for(subs.Start(); subs.More() && PDS.IsNull(); subs.Next()) {
     Handle(StepShape_ShapeRepresentation) SR = 
index 0f5b85e..640c102 100644 (file)
@@ -67,10 +67,7 @@ void StepVisual_StyledItem::SetItem(const StepVisual_StyledItemTarget& theItem)
 
 Handle(StepRepr_RepresentationItem) StepVisual_StyledItem::Item() const
 {
-  if (myItem->IsKind(STANDARD_TYPE(StepRepr_RepresentationItem)))
-    return Handle(StepRepr_RepresentationItem)::DownCast(myItem);
-  else
-    return NULL;
+  return Handle(StepRepr_RepresentationItem)::DownCast(myItem);
 }
 
 StepVisual_StyledItemTarget StepVisual_StyledItem::ItemAP242() const
diff --git a/tests/bugs/step/bug28147 b/tests/bugs/step/bug28147
new file mode 100644 (file)
index 0000000..9cc38ab
--- /dev/null
@@ -0,0 +1,14 @@
+puts "========="
+puts "OCC28147"
+puts "========="
+puts ""
+#######################################################################
+# Data Exchange - NULL dereference while reading color from STEP file
+#######################################################################
+
+ReadStep D [locate_data_file bug28147_file1.stp]
+XShow D
+vfit
+vsetdispmode 1
+
+checkview -screenshot -3d -path ${imagedir}/${test_image}.png