From 5ecc46c08e4090734f50666460041825eb1f2b76 Mon Sep 17 00:00:00 2001 From: vro Date: Mon, 22 May 2017 15:41:14 +0300 Subject: [PATCH] 0027667: OCAF binary persistence hangs on reading truncated CBF file A check on "end of file" is added to the reader. --- .../BinLDrivers_DocumentRetrievalDriver.cxx | 16 ++++++++++++---- tests/bugs/caf/bug27667 | 12 ++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 tests/bugs/caf/bug27667 diff --git a/src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.cxx b/src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.cxx index cd519df753..1bd4996494 100644 --- a/src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.cxx +++ b/src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.cxx @@ -233,8 +233,15 @@ void BinLDrivers_DocumentRetrievalDriver::Read (Standard_IStream& do { BinLDrivers_DocumentSection::ReadTOC (aSection, theIStream); mySections.Append(aSection); - } while - (!aSection.Name().IsEqual((Standard_CString)SHAPESECTION_POS)); + } while(!aSection.Name().IsEqual((Standard_CString)SHAPESECTION_POS) && !theIStream.eof()); + + if (theIStream.eof()) { + // There is no shape section in the file. + WriteMessage (aMethStr + "error: shape section is not found"); + myReaderStatus = PCDM_RS_ReaderException; + return; + } + aDocumentPos = theIStream.tellg(); // position of root label BinLDrivers_VectorOfDocumentSection::Iterator anIterS (mySections); @@ -336,7 +343,8 @@ Standard_Integer BinLDrivers_DocumentRetrievalDriver::ReadSubTree // Read attributes: theIS >> myPAtt; while (theIS && myPAtt.TypeId() > 0 && // not an end marker ? - myPAtt.Id() > 0) { // not a garbage ? + myPAtt.Id() > 0 && // not a garbage ? + !theIS.eof()) { // get a driver according to TypeId Handle(BinMDF_ADriver) aDriver = myDrivers->GetDriver (myPAtt.TypeId()); if (!aDriver.IsNull()) { @@ -386,7 +394,7 @@ Standard_Integer BinLDrivers_DocumentRetrievalDriver::ReadSubTree #if DO_INVERSE aTag = InverseInt (aTag); #endif - while (theIS && aTag >= 0) { // not an end marker ? + while (theIS && aTag >= 0 && !theIS.eof()) { // not an end marker ? // create sub-label TDF_Label aLab = theLabel.FindChild (aTag, Standard_True); diff --git a/tests/bugs/caf/bug27667 b/tests/bugs/caf/bug27667 new file mode 100644 index 0000000000..49ff111e46 --- /dev/null +++ b/tests/bugs/caf/bug27667 @@ -0,0 +1,12 @@ +puts "REQUIRED OCC27667 All: BinLDrivers_DocumentRetrievalDriver: error: shape section is not found" +puts "REQUIRED OCC27667 All: DDocStd_Open : Error" + +puts "================" +puts "OCC27667" +puts "================" +puts "" +####################################################################################### +# OCAF binary persistence hangs on reading truncated CBF file +####################################################################################### + +catch { Open [locate_data_file bug27667_broken_cbf.cbf] D }