]> OCCT Git - occt.git/commitdiff
0032894: Application Framework - Regressions on Ubuntu 20.04
authormpv <mpv@opencascade.com>
Mon, 20 Jun 2022 14:45:27 +0000 (17:45 +0300)
committermpv <mpv@opencascade.com>
Mon, 20 Jun 2022 14:45:27 +0000 (17:45 +0300)
Updated corrupted file reading error management, make memory unit-tests more stable.

src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.cxx
src/BinLDrivers/BinLDrivers_DocumentSection.cxx
src/BinLDrivers/BinLDrivers_DocumentSection.hxx
tests/bugs/caf/bug114
tests/bugs/caf/bug31546

index c6b7d50a494660439739e71b542d19979e1d1b0d..52a83fe71f99eee03ce7e924844b775d76810e1c 100644 (file)
@@ -229,11 +229,12 @@ void BinLDrivers_DocumentRetrievalDriver::Read (Standard_IStream&
   if (aFileVer >= TDocStd_FormatVersion_VERSION_3) {
     BinLDrivers_DocumentSection aSection;
     do {
-      BinLDrivers_DocumentSection::ReadTOC (aSection, theIStream, aFileVer);
+      if (!BinLDrivers_DocumentSection::ReadTOC (aSection, theIStream, aFileVer))
+        break;
       mySections.Append(aSection);
     } while (!aSection.Name().IsEqual (aQuickPart ? ENDSECTION_POS : SHAPESECTION_POS) && !theIStream.eof());
 
-    if (theIStream.eof()) {
+    if (mySections.IsEmpty() || theIStream.eof()) {
       // There is no shape section in the file.
       myMsgDriver->Send (aMethStr + "error: shape section is not found", Message_Fail);
       myReaderStatus = PCDM_RS_ReaderException;
index 97c5b4b8e71089e9dccd16f8cecd939040eca257..547ced34d5c749dafbc13ba45c41b990f08b5543 100644 (file)
@@ -214,14 +214,17 @@ void BinLDrivers_DocumentSection::Write (Standard_OStream&   theStream,
 //purpose  : 
 //=======================================================================
 
-void BinLDrivers_DocumentSection::ReadTOC
-                                (BinLDrivers_DocumentSection& theSection,
+Standard_Boolean BinLDrivers_DocumentSection::ReadTOC (
+                                 BinLDrivers_DocumentSection& theSection,
                                  Standard_IStream&            theStream,
                                  const TDocStd_FormatVersion  theDocFormatVersion)
 {
-  char aBuf[512];
+  static const int THE_BUF_SIZE = 512;
+  char aBuf[THE_BUF_SIZE];
   Standard_Integer aNameBufferSize;
   theStream.read ((char *)&aNameBufferSize, sizeof(Standard_Integer));
+  if (theStream.eof() || aNameBufferSize > THE_BUF_SIZE)
+    return Standard_False;
 #ifdef DO_INVERSE
   aNameBufferSize = InverseSize(aNameBufferSize);
 #endif
@@ -260,4 +263,5 @@ void BinLDrivers_DocumentSection::ReadTOC
     theSection.myValue[1] = aValue[1];
     theSection.myIsPostRead = (aValue[2] != 0);
   }
+  return Standard_True;
 }
index c56f534a73a435685b8b49530e32b4c17d944053..b2e2af837dd9f3ec1a485bb670372a747994bb65 100644 (file)
@@ -73,9 +73,10 @@ public:
                               const TDocStd_FormatVersion theDocFormatVersion);
   
   //! Fill a DocumentSection instance from the data that are read
-  //! from TOC.
-  Standard_EXPORT static void ReadTOC (BinLDrivers_DocumentSection& theSection, Standard_IStream& theIS,
-                                       const TDocStd_FormatVersion theDocFormatVersion);
+  //! from TOC. Returns false in case of the stream reading problem.
+  Standard_EXPORT static Standard_Boolean ReadTOC (BinLDrivers_DocumentSection& theSection,
+                                                   Standard_IStream& theIS,
+                                                   const TDocStd_FormatVersion theDocFormatVersion);
 
 
 
index d3e31a95a2322669557d2a2e886f1ffbc2d9a599..fafb52003c5d172643e81aafbd82ac8a2c3a07c7 100755 (executable)
@@ -20,5 +20,5 @@ for {set i 1} {${i} <= ${i_max}} {incr i} {
 
     # check memory usage (with tolerance equal to half page size)
     lappend listmem [meminfo h]
-    checktrend $listmem 0 1 "Memory leak detected"
+    checktrend $listmem 50 50 "Memory leak detected"
 }
index ef81155c6bddc377f26b7836249b9018f9f8ef93..bf12fa13ebebb149b6354d5bb1035087c4f2358c 100644 (file)
@@ -8,6 +8,11 @@ NewDocument D BinOcaf
 SaveAs D $docname
 Close D
 
+# make the first open/close iteration before checking memory because some filled structures
+# are cleared on start of the next open (like mySections in DocumentRetrievalDriver)
+Open $docname D
+Close D
+
 puts "Executing Load / Close in cycle to see if allocated heap memory grows"
 set listmem {}
 for {set i 1} {$i < 10} {incr i} {