]> OCCT Git - occt.git/commitdiff
0033569: Data Exchange, STEP - Crash when reading multi-body file IR-2024-02-02
authorichesnok <ichesnok@opencascade.com>
Thu, 18 Jan 2024 14:41:27 +0000 (14:41 +0000)
committervglukhik <vglukhik@opencascade.com>
Fri, 2 Feb 2024 12:11:45 +0000 (12:11 +0000)
Datum reading changed in ReadDatums() method:
using DatumSystemAP242 (DatumSystem or DatumReference) array
instead of DatumSystem array (DatumReference)

src/STEPCAFControl/STEPCAFControl_Reader.cxx
tests/bugs/step/bug33569 [new file with mode: 0644]

index 1e5d1227a9dd08889e950ba4798cd505bc2f5e14..9d4a3fc2208dda3e760bd2f06f9f81ee1946711c 100644 (file)
@@ -2553,11 +2553,36 @@ static Standard_Boolean ReadDatums(const Handle(XCAFDoc_ShapeTool) &STool,
   const Handle(StepDimTol_GeometricToleranceWithDatumReference)& GTWDR)
 {
   if (GTWDR.IsNull()) return Standard_False;
-  Handle(StepDimTol_HArray1OfDatumReference) HADR = GTWDR->DatumSystem();
-  if (HADR.IsNull()) return Standard_False;
-  for (Standard_Integer idr = 1; idr <= HADR->Length(); idr++) {
-    Handle(StepDimTol_DatumReference) DR = HADR->Value(idr);
-    Handle(StepDimTol_Datum) aDatum = DR->ReferencedDatum();
+  Handle(StepDimTol_HArray1OfDatumSystemOrReference) aHADSOR = GTWDR->DatumSystemAP242();
+  if (aHADSOR.IsNull())
+  {
+    return Standard_False;
+  }
+  NCollection_List<Handle(StepDimTol_Datum)> aDatumList;
+  for (Standard_Integer idr = 1; idr <= aHADSOR->Length(); idr++)
+  {
+    const StepDimTol_DatumSystemOrReference aDSOR = aHADSOR->Value(idr);
+    if (aDSOR.IsNull()) continue;
+    Handle(StepDimTol_DatumSystem) aDS = aDSOR.DatumSystem();
+    Handle(StepDimTol_DatumReference) aDR = aDSOR.DatumReference();
+    Handle(StepDimTol_Datum) aDatum;
+    if (!aDS.IsNull())
+    {
+      auto aDatumConList = aDS->Constituents();
+      for (Standard_Integer anInd = 1; anInd <= aDatumConList->Length(); anInd++)
+      {
+        Handle(StepDimTol_DatumReferenceCompartment) aDatRefC = aDatumConList->Value(anInd);
+        aDatumList.Append(aDatRefC->Base().Datum());
+      }
+    }
+    else if (!aDR.IsNull())
+    {
+      aDatumList.Append(aDR->ReferencedDatum());
+    }
+  }
+  for(NCollection_List<Handle(StepDimTol_Datum)>::Iterator anIt(aDatumList); anIt.More(); anIt.Next())
+  {
+    Handle(StepDimTol_Datum) aDatum = anIt.Value();
     if (aDatum.IsNull()) continue;
     Interface_EntityIterator subs4 = graph.Sharings(aDatum);
     for (subs4.Start(); subs4.More(); subs4.Next()) {
diff --git a/tests/bugs/step/bug33569 b/tests/bugs/step/bug33569
new file mode 100644 (file)
index 0000000..0f05525
--- /dev/null
@@ -0,0 +1,13 @@
+puts "================"
+puts "0033569: Data Exchange, STEP - Crash when reading multi-body file"
+puts "================"
+
+ReadStep D [locate_data_file bug33569.stp]
+
+set result [XDumpNbDGTs D] 
+
+regexp {NbOfAttachedDatum +: +([0-9]+)} $result full nb
+
+if { $nb != 26} {
+  puts "Error: Number of Datums incorrect"
+}