From f8c45c2f0df26c4da5d8367c737f83b84952b019 Mon Sep 17 00:00:00 2001 From: mpv Date: Mon, 20 Jun 2022 17:45:27 +0300 Subject: [PATCH] 0032894: Application Framework - Regressions on Ubuntu 20.04 Updated corrupted file reading error management, make memory unit-tests more stable. --- .../BinLDrivers_DocumentRetrievalDriver.cxx | 5 +++-- src/BinLDrivers/BinLDrivers_DocumentSection.cxx | 10 +++++++--- src/BinLDrivers/BinLDrivers_DocumentSection.hxx | 7 ++++--- tests/bugs/caf/bug114 | 2 +- tests/bugs/caf/bug31546 | 5 +++++ 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.cxx b/src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.cxx index c6b7d50a49..52a83fe71f 100644 --- a/src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.cxx +++ b/src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.cxx @@ -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; diff --git a/src/BinLDrivers/BinLDrivers_DocumentSection.cxx b/src/BinLDrivers/BinLDrivers_DocumentSection.cxx index 97c5b4b8e7..547ced34d5 100644 --- a/src/BinLDrivers/BinLDrivers_DocumentSection.cxx +++ b/src/BinLDrivers/BinLDrivers_DocumentSection.cxx @@ -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; } diff --git a/src/BinLDrivers/BinLDrivers_DocumentSection.hxx b/src/BinLDrivers/BinLDrivers_DocumentSection.hxx index c56f534a73..b2e2af837d 100644 --- a/src/BinLDrivers/BinLDrivers_DocumentSection.hxx +++ b/src/BinLDrivers/BinLDrivers_DocumentSection.hxx @@ -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); diff --git a/tests/bugs/caf/bug114 b/tests/bugs/caf/bug114 index d3e31a95a2..fafb52003c 100755 --- a/tests/bugs/caf/bug114 +++ b/tests/bugs/caf/bug114 @@ -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" } diff --git a/tests/bugs/caf/bug31546 b/tests/bugs/caf/bug31546 index ef81155c6b..bf12fa13eb 100644 --- a/tests/bugs/caf/bug31546 +++ b/tests/bugs/caf/bug31546 @@ -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} {