From: ika Date: Tue, 23 Aug 2016 08:06:03 +0000 (+0300) Subject: 0027645: Data Exchange - access violation when reading STEP AP242 file X-Git-Tag: V7_1_0_beta~181 X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=commitdiff_plain;h=f3ec3b372c62db955a5e2ead4fcf71ab15553f37 0027645: Data Exchange - access violation when reading STEP AP242 file Fix exceptions, add test cases. Small correction of test cases for issue CR27645 --- diff --git a/src/STEPCAFControl/STEPCAFControl_Reader.cxx b/src/STEPCAFControl/STEPCAFControl_Reader.cxx index 439873f12a..eab34c7f47 100644 --- a/src/STEPCAFControl/STEPCAFControl_Reader.cxx +++ b/src/STEPCAFControl/STEPCAFControl_Reader.cxx @@ -2489,11 +2489,11 @@ static Standard_Boolean readDatumsAP242(const Handle(Standard_Transient)& theEnt { for(Standard_Integer k = aModifE->Lower(); k <= aModifE->Upper(); k++) { - if(aModifE->Value(k).CaseNumber() == 1) + if(aModifE->Value(k).CaseNumber() == 2) aXCAFModifiers.Append( (XCAFDimTolObjects_DatumSingleModif)aModifE->Value(k). SimpleDatumReferenceModifierMember()->Value()); - else if (aModifE->Value(k).CaseNumber() == 2) + else if (aModifE->Value(k).CaseNumber() == 1) { aXCAFModifWithVal = (XCAFDimTolObjects_DatumModifWithValue)(aModifE->Value(k).DatumReferenceModifierWithValue()->ModifierType() + 1); Standard_Real aVal = aModifE->Value(k).DatumReferenceModifierWithValue()->ModifierValue()->ValueComponent(); @@ -2582,6 +2582,22 @@ static TDF_Label createGDTObjectInXCAF(const Handle(Standard_Transient)& theEnt, { return aGDTL; } + // protection against invalid input + if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) { + Handle(StepDimTol_GeometricTolerance) aGeomTol = Handle(StepDimTol_GeometricTolerance)::DownCast(theEnt); + if (aGeomTol->TolerancedShapeAspect().IsNull()) + return aGDTL; + } + if (theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize))) { + Handle(StepShape_DimensionalSize) aDim = Handle(StepShape_DimensionalSize)::DownCast(theEnt); + if (aDim->AppliesTo().IsNull()) + return aGDTL; + } + if (theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation))) { + Handle(StepShape_DimensionalLocation) aDim = Handle(StepShape_DimensionalLocation)::DownCast(theEnt); + if (aDim->RelatedShapeAspect().IsNull() || aDim->RelatingShapeAspect().IsNull()) + return aGDTL; + } Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( theDoc->Main() ); Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool( theDoc->Main() ); diff --git a/src/STEPCAFControl/STEPCAFControl_Writer.cxx b/src/STEPCAFControl/STEPCAFControl_Writer.cxx index 3636257479..a69849ae42 100644 --- a/src/STEPCAFControl/STEPCAFControl_Writer.cxx +++ b/src/STEPCAFControl/STEPCAFControl_Writer.cxx @@ -2905,7 +2905,7 @@ static Handle(StepDimTol_HArray1OfDatumSystemOrReference) WriteDatumSystem(const if (aDatumSeqPos.Length() == 1) { // Datum entity Handle(Standard_Transient) aFDValue; - if (theDatumMap.Find(aDatumSeqPos.Value(1)->GetName()->String(), aFDValue)) + if (theDatumMap.Find(aDatumSeqPos.Value(1)->GetName()->String(), aFDValue) && !aFDValue.IsNull()) aFirstDatum = Handle(StepDimTol_Datum)::DownCast (aFDValue); aDatumRef.SetValue(aFirstDatum); // Modifiers @@ -2945,7 +2945,7 @@ static Handle(StepDimTol_HArray1OfDatumSystemOrReference) WriteDatumSystem(const // Add Datum_Reference_Modifier_With_Value if (!anElemModifiers.IsNull()) { Handle(StepDimTol_DatumReferenceModifierWithValue) aDRMWV = - anElemModifiers->Value(aModifiers->Length()).DatumReferenceModifierWithValue(); + anElemModifiers->Value(anElemModifiers->Length()).DatumReferenceModifierWithValue(); if (!aDRMWV.IsNull()) { Model->AddWithRefs(aDRMWV); } @@ -3701,15 +3701,16 @@ Standard_Boolean STEPCAFControl_Writer::WriteDGTsAP242 (const Handle(XSControl_W for (Standard_Integer shIt = 1; shIt <= aFirstShapeL.Length(); shIt++) { TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aFirstShapeL.Value(shIt)); Handle(StepRepr_ShapeAspect) aSA = WriteShapeAspect(WS, aDimensionL, aShape, dummyRC, dummyGISU); - if (aCSA.IsNull() && !aSA.IsNull()) + if (aSA.IsNull()) + continue; + if (aCSA.IsNull()) { aCSA = new StepRepr_CompositeShapeAspect(); aCSA->Init(aSA->Name(), aSA->Description(), aSA->OfShape(), aSA->ProductDefinitional()); aModel->AddWithRefs(aCSA); - if (!aSA.IsNull()) { - Handle(StepRepr_ShapeAspectRelationship) aSAR = new StepRepr_ShapeAspectRelationship(); - aSAR->Init(new TCollection_HAsciiString(), Standard_False, new TCollection_HAsciiString(), aCSA, aSA); - aModel->AddWithRefs(aSAR); } + Handle(StepRepr_ShapeAspectRelationship) aSAR = new StepRepr_ShapeAspectRelationship(); + aSAR->Init(new TCollection_HAsciiString(), Standard_False, new TCollection_HAsciiString(), aCSA, aSA); + aModel->AddWithRefs(aSAR); if (aRC.IsNull() && !dummyRC.IsNull()) aRC = dummyRC; } diff --git a/tests/gdt/export/A6 b/tests/gdt/export/A6 new file mode 100644 index 0000000000..33d7a0034a --- /dev/null +++ b/tests/gdt/export/A6 @@ -0,0 +1,19 @@ +# !!!! This file is generated automatically, do not edit manually! See end script +set filename bug27645_nist_ftc_06_asme1_cr3000_rd.prt.stp +puts "TODO CR26859 ALL:Error : 3 differences with reference data found :" +puts "TODO CR26859 ALL:Error on writing file" +set ref_data { + + NbOfDimensions : 20 + NbOfDimensionalSize : 18 + NbOfDimensionalLocation: 2 + NbOfAngular : 0 + NbOfWithPath : 0 + NbOfTolerances : 22 + NbOfGTWithModifiers : 4 + NbOfGTWithMaxTolerance : 0 + NbOfGTWithDatums : 3 + NbOfDatumFeature : 3 + NbOfAttachedDatum : 3 + NbOfDatumTarget : 0 +} diff --git a/tests/gdt/export/A7 b/tests/gdt/export/A7 new file mode 100644 index 0000000000..51a3580eae --- /dev/null +++ b/tests/gdt/export/A7 @@ -0,0 +1,19 @@ +# !!!! This file is generated automatically, do not edit manually! See end script +set filename bug27645_nist_ftc_06_asme1_ct5240_rd.stp +puts "TODO CR26859 ALL:Error : 3 differences with reference data found :" +puts "TODO CR26859 ALL:Error on writing file" +set ref_data { + + NbOfDimensions : 22 + NbOfDimensionalSize : 14 + NbOfDimensionalLocation: 8 + NbOfAngular : 0 + NbOfWithPath : 0 + NbOfTolerances : 21 + NbOfGTWithModifiers : 4 + NbOfGTWithMaxTolerance : 0 + NbOfGTWithDatums : 20 + NbOfDatumFeature : 6 + NbOfAttachedDatum : 46 + NbOfDatumTarget : 0 +} diff --git a/tests/gdt/export/A8 b/tests/gdt/export/A8 new file mode 100644 index 0000000000..4e9be97b0e --- /dev/null +++ b/tests/gdt/export/A8 @@ -0,0 +1,19 @@ +# !!!! This file is generated automatically, do not edit manually! See end script +set filename bug27645_nist_ftc_06_asme1_ct5240_rd-1.stp +puts "TODO CR26859 ALL:Error : 3 differences with reference data found :" +puts "TODO CR26859 ALL:Error on writing file" +set ref_data { + + NbOfDimensions : 22 + NbOfDimensionalSize : 14 + NbOfDimensionalLocation: 8 + NbOfAngular : 0 + NbOfWithPath : 0 + NbOfTolerances : 21 + NbOfGTWithModifiers : 4 + NbOfGTWithMaxTolerance : 0 + NbOfGTWithDatums : 20 + NbOfDatumFeature : 6 + NbOfAttachedDatum : 46 + NbOfDatumTarget : 0 +} diff --git a/tests/gdt/export/A9 b/tests/gdt/export/A9 new file mode 100644 index 0000000000..751ff771ca --- /dev/null +++ b/tests/gdt/export/A9 @@ -0,0 +1,19 @@ +# !!!! This file is generated automatically, do not edit manually! See end script +set filename bug27645_nist_ftc_08_asme1_cr3000_rc.prt.stp +puts "TODO CR26859 ALL:Error : 1 differences with reference data found :" +puts "TODO CR26859 ALL:Error on writing file" +set ref_data { + + NbOfDimensions : 10 + NbOfDimensionalSize : 10 + NbOfDimensionalLocation: 0 + NbOfAngular : 0 + NbOfWithPath : 0 + NbOfTolerances : 30 + NbOfGTWithModifiers : 14 + NbOfGTWithMaxTolerance : 0 + NbOfGTWithDatums : 1 + NbOfDatumFeature : 2 + NbOfAttachedDatum : 2 + NbOfDatumTarget : 0 +} diff --git a/tests/gdt/export/B1 b/tests/gdt/export/B1 new file mode 100644 index 0000000000..4b92217185 --- /dev/null +++ b/tests/gdt/export/B1 @@ -0,0 +1,18 @@ +# !!!! This file is generated automatically, do not edit manually! See end script +set filename bug27645_nist_ftc_08_asme1_ct5240_rc.stp + +set ref_data { + + NbOfDimensions : 10 + NbOfDimensionalSize : 9 + NbOfDimensionalLocation: 1 + NbOfAngular : 0 + NbOfWithPath : 0 + NbOfTolerances : 29 + NbOfGTWithModifiers : 22 + NbOfGTWithMaxTolerance : 0 + NbOfGTWithDatums : 28 + NbOfDatumFeature : 10 + NbOfAttachedDatum : 71 + NbOfDatumTarget : 0 +} diff --git a/tests/gdt/export/B2 b/tests/gdt/export/B2 new file mode 100644 index 0000000000..85c54f0a84 --- /dev/null +++ b/tests/gdt/export/B2 @@ -0,0 +1,18 @@ +# !!!! This file is generated automatically, do not edit manually! See end script +set filename bug27645_nist_ftc_08_asme1_ct5240_rc-1.stp + +set ref_data { + + NbOfDimensions : 10 + NbOfDimensionalSize : 9 + NbOfDimensionalLocation: 1 + NbOfAngular : 0 + NbOfWithPath : 0 + NbOfTolerances : 29 + NbOfGTWithModifiers : 22 + NbOfGTWithMaxTolerance : 0 + NbOfGTWithDatums : 28 + NbOfDatumFeature : 10 + NbOfAttachedDatum : 71 + NbOfDatumTarget : 0 +} diff --git a/tests/gdt/export/B3 b/tests/gdt/export/B3 new file mode 100644 index 0000000000..8cfcd13402 --- /dev/null +++ b/tests/gdt/export/B3 @@ -0,0 +1,19 @@ +# !!!! This file is generated automatically, do not edit manually! See end script +set filename bug27645_nist_ftc_09_asme1_cr3000_rd.prt.stp +puts "TODO CR26859 ALL:Error : 1 differences with reference data found :" +puts "TODO CR26859 ALL:Error on writing file" +set ref_data { + + NbOfDimensions : 21 + NbOfDimensionalSize : 19 + NbOfDimensionalLocation: 2 + NbOfAngular : 0 + NbOfWithPath : 0 + NbOfTolerances : 29 + NbOfGTWithModifiers : 6 + NbOfGTWithMaxTolerance : 0 + NbOfGTWithDatums : 0 + NbOfDatumFeature : 0 + NbOfAttachedDatum : 0 + NbOfDatumTarget : 0 +} diff --git a/tests/gdt/export/B4 b/tests/gdt/export/B4 new file mode 100644 index 0000000000..65994b3ebd --- /dev/null +++ b/tests/gdt/export/B4 @@ -0,0 +1,18 @@ +# !!!! This file is generated automatically, do not edit manually! See end script +set filename bug27645_nist_ftc_09_asme1_ct5240_rd.stp + +set ref_data { + + NbOfDimensions : 22 + NbOfDimensionalSize : 15 + NbOfDimensionalLocation: 7 + NbOfAngular : 0 + NbOfWithPath : 0 + NbOfTolerances : 28 + NbOfGTWithModifiers : 8 + NbOfGTWithMaxTolerance : 0 + NbOfGTWithDatums : 28 + NbOfDatumFeature : 6 + NbOfAttachedDatum : 69 + NbOfDatumTarget : 0 +} diff --git a/tests/gdt/export/B5 b/tests/gdt/export/B5 new file mode 100644 index 0000000000..0dd94c987a --- /dev/null +++ b/tests/gdt/export/B5 @@ -0,0 +1,18 @@ +# !!!! This file is generated automatically, do not edit manually! See end script +set filename bug27645_nist_ftc_09_asme1_ct5240_rd-1.stp + +set ref_data { + + NbOfDimensions : 22 + NbOfDimensionalSize : 15 + NbOfDimensionalLocation: 7 + NbOfAngular : 0 + NbOfWithPath : 0 + NbOfTolerances : 28 + NbOfGTWithModifiers : 8 + NbOfGTWithMaxTolerance : 0 + NbOfGTWithDatums : 28 + NbOfDatumFeature : 6 + NbOfAttachedDatum : 69 + NbOfDatumTarget : 0 +}