]> OCCT Git - occt-copy.git/commitdiff
0027454: Application hangs while opening a non-OCAF XML file
authormsv <msv@opencascade.com>
Fri, 29 Apr 2016 16:31:13 +0000 (19:31 +0300)
committermsv <msv@opencascade.com>
Tue, 10 May 2016 15:25:08 +0000 (18:25 +0300)
1) Add protection against accessing null pointer in PCDM_ReadWriter::FileFormat.

2) In LDOM_XmlReader::ReadRecord, take into account that the character '>' can have no special meaning (e.g., in a text), and we must read the data behind this character to complete the current tag reading. This treatment concerns the mode of work when myTagPerStep is true.

3) Create a test case of reading of XML file not related to OCAF document.

src/LDOM/LDOM_XmlReader.cxx
src/PCDM/PCDM_ReadWriter.cxx
tests/bugs/caf/bug27454 [new file with mode: 0644]
tests/bugs/caf/bug27454_1 [new file with mode: 0644]

index e51cb76e96e07ec2480b08021c65419eed63b688..1085bac46f34dc6eed47c400fffd27838dee0d78 100644 (file)
@@ -108,6 +108,8 @@ LDOM_XmlReader::RecordType LDOM_XmlReader::ReadRecord (Standard_IStream& theIStr
       }
       else if (myTagPerStep && aHasRead)
       {
+        // in myTagPerStep mode, we should parse the buffer to the end before
+        // getting more characters from the stream.
       }
       else
       {
@@ -226,6 +228,7 @@ LDOM_XmlReader::RecordType LDOM_XmlReader::ReadRecord (Standard_IStream& theIStr
         aState = STATE_TEXT;
         aStartData = myPtr;
         myPtr = myEndPtr;
+        aHasRead = Standard_False;
       }   // end of checking in STATE_WAITING
       continue;
 
@@ -245,6 +248,7 @@ LDOM_XmlReader::RecordType LDOM_XmlReader::ReadRecord (Standard_IStream& theIStr
         return XML_HEADER;
       }
       myPtr = myEndPtr - 1;
+      aHasRead = Standard_False;
       continue;
 
       // Checking the characters in STATE_DOCTYPE, seek for "]>" sequence
@@ -265,6 +269,7 @@ LDOM_XmlReader::RecordType LDOM_XmlReader::ReadRecord (Standard_IStream& theIStr
         }
       }
       myPtr = myEndPtr - 1;
+      aHasRead = Standard_False;
       continue;
 
     state_doctype_markup:
@@ -283,6 +288,7 @@ LDOM_XmlReader::RecordType LDOM_XmlReader::ReadRecord (Standard_IStream& theIStr
         return XML_DOCTYPE;
       }
       myPtr = myEndPtr - 1;
+      aHasRead = Standard_False;
       continue;
 
         // Checking the characters in STATE_COMMENT, seek for "-->" sequence
@@ -304,6 +310,7 @@ LDOM_XmlReader::RecordType LDOM_XmlReader::ReadRecord (Standard_IStream& theIStr
         }
       }
       myPtr = myEndPtr - 2;
+      aHasRead = Standard_False;
       continue;
 
         // Checking the characters in STATE_TEXT, seek for "<"
@@ -317,6 +324,7 @@ LDOM_XmlReader::RecordType LDOM_XmlReader::ReadRecord (Standard_IStream& theIStr
         return XML_TEXT;
       }
       myPtr = myEndPtr;
+      aHasRead = Standard_False;
       continue;
 
         // Checking the characters in STATE_CDATA, seek for "]]"
@@ -335,6 +343,7 @@ LDOM_XmlReader::RecordType LDOM_XmlReader::ReadRecord (Standard_IStream& theIStr
         return XML_CDATA;
       }
       myPtr = myEndPtr - 1;
+      aHasRead = Standard_False;
       continue;
 
         // Checking the characters in STATE_ELEMENT, seek the end of TagName
@@ -490,8 +499,11 @@ attr_name:
           myPtr = aPtr + 1;
           aStartData = NULL;
           aState = STATE_ATTRIBUTE_NAME;
-        } else
+        }
+        else {
           myPtr = myEndPtr;
+          aHasRead = Standard_False;
+        }
         continue;
       }
         // Checking the characters in STATE_ELEMENT_END, seek for ">"
@@ -505,6 +517,7 @@ attr_name:
         return XML_END_ELEMENT;
       }
       myPtr = myEndPtr;
+      aHasRead = Standard_False;
       continue;
     }
   }
index fb25d7cbfc107bbd4b776c894f3e37f996b00152..bd01ac9ceacf5e841f57f0898c4e2d62d1dbdfea 100644 (file)
@@ -152,12 +152,16 @@ TCollection_ExtendedString PCDM_ReadWriter::FileFormat (Standard_IStream& theISt
 {
   TCollection_ExtendedString aFormat;
 
-  Storage_BaseDriver* aFileDriver;
+  Storage_BaseDriver* aFileDriver = 0L;
   if (PCDM::FileDriverType (theIStream, aFileDriver) == PCDM_TOFD_XmlFile)
   {
     return ::TryXmlDriverType (theIStream);
   }
+  if (!aFileDriver)
+  {
+    // type is not recognized, return empty string
+    return aFormat;
+  }
 
   aFileDriver->ReadCompleteInfo (theIStream, theData);
 
diff --git a/tests/bugs/caf/bug27454 b/tests/bugs/caf/bug27454
new file mode 100644 (file)
index 0000000..e146f3b
--- /dev/null
@@ -0,0 +1,19 @@
+puts "REQUIRED All: DDocStd_Open : Error"
+
+puts "========"
+puts "OCC27454"
+puts "========"
+puts ""
+###################################################
+## Application hangs while opening a non-OCAF XML file
+###################################################
+
+cpulimit 10
+
+catch {Open [locate_data_file bug27454_test.xml] D -stream} msg
+
+cpulimit
+
+if ![regexp {DDocStd_Open : Error} $msg] {
+  puts "Error: reader did not report an error reading the file of unknown format"
+}
\ No newline at end of file
diff --git a/tests/bugs/caf/bug27454_1 b/tests/bugs/caf/bug27454_1
new file mode 100644 (file)
index 0000000..f146be3
--- /dev/null
@@ -0,0 +1,16 @@
+puts "========"
+puts "OCC27454"
+puts "========"
+puts ""
+###################################################
+## Application hangs while opening a non-OCAF XML file
+###################################################
+
+if [info exists D] {unset D}
+Open [locate_data_file shape_tracking.ocaf.xml] D -stream
+
+if {[dtyp D] != "TDocStd_Document"} {
+  puts "Error: XML OCAF document read failure"
+}
+
+Close D