]> OCCT Git - occt.git/commitdiff
0031711: Data Exchange - STEPCAFControl_Reader hangs on attached file in an infinite...
authordpasukhi <dpasukhi@opencascade.com>
Tue, 1 Sep 2020 07:47:20 +0000 (10:47 +0300)
committerbugmaster <bugmaster@opencascade.com>
Fri, 18 Sep 2020 14:46:48 +0000 (17:46 +0300)
Add check if .step external file is the same main file.

src/STEPCAFControl/STEPCAFControl_Reader.cxx
src/STEPConstruct/STEPConstruct_ExternRefs.cxx
src/STEPConstruct/STEPConstruct_ExternRefs.hxx
tests/bugs/step/bug31711 [new file with mode: 0644]

index 1d6f28e2fec845671de145cac5a86f65eabcd065..37fc818ddabf2e32ac9079028a58af776c18f05b 100644 (file)
@@ -46,6 +46,7 @@
 #include <StepBasic_SiUnit.hxx>
 #include <StepBasic_SiUnitAndLengthUnit.hxx>
 #include <StepBasic_Unit.hxx>
+#include <StepBasic_DocumentFile.hxx>
 #include <STEPCAFControl_Controller.hxx>
 #include <STEPCAFControl_DataMapIteratorOfDataMapOfShapePD.hxx>
 #include <STEPCAFControl_DataMapOfPDExternFile.hxx>
@@ -623,8 +624,10 @@ Standard_Boolean STEPCAFControl_Reader::Transfer (STEPControl_Reader &reader,
     }
   }
 
-  // get directory name of the main file
+  // get file name and directory name of the main file
   OSD_Path mainfile(reader.WS()->LoadedFile());
+  TCollection_AsciiString aMainName;
+  aMainName = mainfile.Name() + mainfile.Extension();
   mainfile.SetName("");
   mainfile.SetExtension("");
   TCollection_AsciiString dpath;
@@ -674,6 +677,13 @@ Standard_Boolean STEPCAFControl_Reader::Transfer (STEPControl_Reader &reader,
     TCollection_AsciiString fullname = OSD_Path::AbsolutePath(dpath, filename);
     if (fullname.Length() <= 0) fullname = filename;
 
+    // check for not the same file
+    TCollection_AsciiString aMainFullName = OSD_Path::AbsolutePath(dpath, aMainName);
+    if (TCollection_AsciiString::IsSameString(aMainFullName,fullname,Standard_False)) {
+      TP->AddWarning(ExtRefs.DocFile(i), "External reference file is the same main file");
+      continue; // not a valid extern ref
+    }
+
     /*
         char fullname[1024];
         char *mainfile = reader.WS()->LoadedFile();
index f2c110efa30b31f901014a1a5be3eb07a3932dc9..a6773ece073a46d476610757264c8db45810766a 100644 (file)
@@ -468,6 +468,16 @@ Handle(StepBasic_ProductDefinition) STEPConstruct_ExternRefs::ProdDef (const Sta
   return Handle(StepBasic_ProductDefinition)::DownCast( myShapes(num) );
 }
 
+//=======================================================================
+//function : DocFile
+//purpose  : 
+//=======================================================================
+
+Handle(StepBasic_DocumentFile) STEPConstruct_ExternRefs::DocFile(const Standard_Integer num) const
+{
+  return Handle(StepBasic_DocumentFile)::DownCast(myDocFiles.Value(num));
+}
+
 //=======================================================================
 //function : Format
 //purpose  : 
index 47fa6162a9846752429d1e03dce7b720ecc04f14..0d759c37182e46071eac506116df2472b4453ce6 100644 (file)
@@ -82,6 +82,11 @@ public:
   //! is not associated to SDR in a proper way.
   Standard_EXPORT Handle(StepBasic_ProductDefinition) ProdDef (const Standard_Integer num) const;
   
+  //! Returns DocumentFile to which numth extern reference
+  //! is associated.
+  //! Returns Null if cannot be detected.
+  Standard_EXPORT Handle(StepBasic_DocumentFile) DocFile (const Standard_Integer num) const;
+
   //! Returns format identification string for the extern document
   //! Returns Null handle if format is not defined
   Standard_EXPORT Handle(TCollection_HAsciiString) Format (const Standard_Integer num) const;
diff --git a/tests/bugs/step/bug31711 b/tests/bugs/step/bug31711
new file mode 100644 (file)
index 0000000..3da4c86
--- /dev/null
@@ -0,0 +1,23 @@
+puts "=========="
+puts "0031711: Data Exchange - STEPCAFControl_Reader hangs on attached file in an infinite loop"
+puts "=========="
+puts ""
+
+# to prevent loops limit to 2 minute
+cpulimit 120
+
+set path_first [locate_data_file bug31711.stp]
+regsub -all {/} $path_first {\\} path_second
+
+ReadStep D_First $path_first
+
+XGetOneShape result D_First 
+checkshape result
+checknbshapes result -solid 1 -shell 1 -face 3687 -wire 4020
+
+if { [regexp -nocase "Windows" $tcl_platform(os)] != 0 } {
+  ReadStep D_Second $path_second
+}
+
+# return cpu limit
+cpulimit 1000
\ No newline at end of file