Преглед на файлове

Zend_Search_Lucene: correct exception is thrown for corrupted .docx, .pptx and .xlsx files. ZF-7681.

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@19034 44c647ce-9c0f-0410-b52a-842ac1e357ba
alexander преди 16 години
родител
ревизия
ae0a07c293
променени са 3 файла, в които са добавени 21 реда и са изтрити 3 реда
  1. 7 1
      library/Zend/Search/Lucene/Document/Docx.php
  2. 7 1
      library/Zend/Search/Lucene/Document/Pptx.php
  3. 7 1
      library/Zend/Search/Lucene/Document/Xlsx.php

+ 7 - 1
library/Zend/Search/Lucene/Document/Docx.php

@@ -47,6 +47,7 @@ class Zend_Search_Lucene_Document_Docx extends Zend_Search_Lucene_Document_OpenX
      *
      * @param string  $fileName
      * @param boolean $storeContent
+     * @throws Zend_Search_Lucene_Exception
      */
     private function __construct($fileName, $storeContent) {
         // Document data holders
@@ -58,7 +59,12 @@ class Zend_Search_Lucene_Document_Docx extends Zend_Search_Lucene_Document_OpenX
         $package->open($fileName);
 
         // Read relations and search for officeDocument
-        $relations = simplexml_load_string($package->getFromName('_rels/.rels'));
+        $relationsXml = $package->getFromName('_rels/.rels');
+        if ($relationsXml === false) {
+            require_once 'Zend/Search/Lucene/Exception.php';
+            throw new Zend_Search_Lucene_Exception('Invalid archive or corrupted .docx file.');
+        }
+        $relations = simplexml_load_string($relationsXml);
         foreach($relations->Relationship as $rel) {
             if ($rel ["Type"] == Zend_Search_Lucene_Document_OpenXml::SCHEMA_OFFICEDOCUMENT) {
                 // Found office document! Read in contents...

+ 7 - 1
library/Zend/Search/Lucene/Document/Pptx.php

@@ -70,6 +70,7 @@ class Zend_Search_Lucene_Document_Pptx extends Zend_Search_Lucene_Document_OpenX
      *
      * @param string  $fileName
      * @param boolean $storeContent
+     * @throws Zend_Search_Lucene_Exception
      */
     private function __construct($fileName, $storeContent)
     {
@@ -84,7 +85,12 @@ class Zend_Search_Lucene_Document_Pptx extends Zend_Search_Lucene_Document_OpenX
         $package->open($fileName);
 
         // Read relations and search for officeDocument
-        $relations = simplexml_load_string($package->getFromName("_rels/.rels"));
+        $relationsXml = $package->getFromName('_rels/.rels');
+        if ($relationsXml === false) {
+            require_once 'Zend/Search/Lucene/Exception.php';
+            throw new Zend_Search_Lucene_Exception('Invalid archive or corrupted .pptx file.');
+        }
+        $relations = simplexml_load_string($relationsXml);
         foreach ($relations->Relationship as $rel) {
             if ($rel["Type"] == Zend_Search_Lucene_Document_OpenXml::SCHEMA_OFFICEDOCUMENT) {
                 // Found office document! Search for slides...

+ 7 - 1
library/Zend/Search/Lucene/Document/Xlsx.php

@@ -77,6 +77,7 @@ class Zend_Search_Lucene_Document_Xlsx extends Zend_Search_Lucene_Document_OpenX
      *
      * @param string  $fileName
      * @param boolean $storeContent
+     * @throws Zend_Search_Lucene_Exception
      */
     private function __construct($fileName, $storeContent)
     {
@@ -91,7 +92,12 @@ class Zend_Search_Lucene_Document_Xlsx extends Zend_Search_Lucene_Document_OpenX
         $package->open($fileName);
 
         // Read relations and search for officeDocument
-        $relations = simplexml_load_string($package->getFromName("_rels/.rels"));
+        $relationsXml = $package->getFromName('_rels/.rels');
+        if ($relationsXml === false) {
+            require_once 'Zend/Search/Lucene/Exception.php';
+            throw new Zend_Search_Lucene_Exception('Invalid archive or corrupted .xlsx file.');
+        }
+        $relations = simplexml_load_string($relationsXml);
         foreach ($relations->Relationship as $rel) {
             if ($rel["Type"] == Zend_Search_Lucene_Document_OpenXml::SCHEMA_OFFICEDOCUMENT) {
                 // Found office document! Read relations for workbook...