Ver Fonte

Zend_Pdf. Zend_Search_Lucene: fix file reading. Fixes [ZF-10697].

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23394 44c647ce-9c0f-0410-b52a-842ac1e357ba
alexander há 15 anos atrás
pai
commit
03d6129ce0

+ 11 - 3
library/Zend/Pdf/Parser.php

@@ -367,14 +367,22 @@ class Zend_Pdf_Parser
                 throw new Zend_Pdf_Exception( "Can not open '$source' file for reading." );
             }
 
+            $data = '';
             $byteCount = filesize($source);
+            while ($byteCount > 0 && !feof($pdfFile)) {
+                $nextBlock = fread($pdfFile, $byteCount);
+                if ($nextBlock === false) {
+                    require_once 'Zend/Pdf/Exception.php';
+                    throw new Zend_Pdf_Exception( "Error occured while '$source' file reading." );
+                }
 
-            $data = fread($pdfFile, $byteCount);
-            $byteCount -= strlen($data);
-            while ( $byteCount > 0 && ($nextBlock = fread($pdfFile, $byteCount)) != false ) {
                 $data .= $nextBlock;
                 $byteCount -= strlen($nextBlock);
             }
+            if ($byteCount != 0) {
+                require_once 'Zend/Pdf/Exception.php';
+                throw new Zend_Pdf_Exception( "Error occured while '$source' file reading." );
+            }
             fclose($pdfFile);
 
             $this->_stringParser = new Zend_Pdf_StringParser($data, $factory);

+ 18 - 7
library/Zend/Pdf/Resource/Image/Jpeg.php

@@ -102,19 +102,30 @@ class Zend_Pdf_Resource_Image_Jpeg extends Zend_Pdf_Resource_Image
         }
         $byteCount = filesize($imageFileName);
         $this->_resource->value = '';
-        while ( $byteCount > 0 && ($nextBlock = fread($imageFile, $byteCount)) != false ) {
+
+        while ($byteCount > 0 && !feof($imageFile)) {
+            $nextBlock = fread($imageFile, $byteCount);
+            if ($nextBlock === false) {
+                require_once 'Zend/Pdf/Exception.php';
+                throw new Zend_Pdf_Exception( "Error occured while '$imageFileName' file reading." );
+            }
+
             $this->_resource->value .= $nextBlock;
             $byteCount -= strlen($nextBlock);
         }
+        if ($byteCount != 0) {
+            require_once 'Zend/Pdf/Exception.php';
+            throw new Zend_Pdf_Exception( "Error occured while '$imageFileName' file reading." );
+        }
         fclose($imageFile);
         $this->_resource->skipFilters();
 
-    $this->_width = $imageInfo[0];
-    $this->_height = $imageInfo[1];
-    $this->_imageProperties = array();
-    $this->_imageProperties['bitDepth'] = $imageInfo['bits'];
-    $this->_imageProperties['jpegImageType'] = $imageInfo[2];
-    $this->_imageProperties['jpegColorType'] = $imageInfo['channels'];
+        $this->_width  = $imageInfo[0];
+        $this->_height = $imageInfo[1];
+        $this->_imageProperties = array();
+        $this->_imageProperties['bitDepth'] = $imageInfo['bits'];
+        $this->_imageProperties['jpegImageType'] = $imageInfo[2];
+        $this->_imageProperties['jpegColorType'] = $imageInfo['channels'];
     }
 
     /**

+ 10 - 4
library/Zend/Pdf/Resource/Image/Png.php

@@ -123,10 +123,16 @@ class Zend_Pdf_Resource_Image_Png extends Zend_Pdf_Resource_Image
          * The following loop processes PNG chunks. 4 Byte Longs are packed first give the chunk length
          * followed by the chunk signature, a four byte code. IDAT and IEND are manditory in any PNG.
          */
-        while(($chunkLengthBytes = fread($imageFile, 4)) !== false) {
-            $chunkLengthtmp         = unpack('Ni', $chunkLengthBytes);
-            $chunkLength            = $chunkLengthtmp['i'];
-            $chunkType                      = fread($imageFile, 4);
+        while (!feof($imageFile)) {
+            $chunkLengthBytes = fread($imageFile, 4);
+            if ($chunkLengthBytes === false) {
+                require_once 'Zend/Pdf/Exception.php';
+                throw new Zend_Pdf_Exception('Error ocuured while image file reading.');
+            }
+
+            $chunkLengthtmp = unpack('Ni', $chunkLengthBytes);
+            $chunkLength    = $chunkLengthtmp['i'];
+            $chunkType      = fread($imageFile, 4);
             switch($chunkType) {
                 case 'IDAT': //Image Data
                     /*

+ 12 - 1
library/Zend/Search/Lucene/Storage/File/Filesystem.php

@@ -159,10 +159,21 @@ class Zend_Search_Lucene_Storage_File_Filesystem extends Zend_Search_Lucene_Stor
         }
 
         $data = '';
-        while ( $length > 0 && ($nextBlock = fread($this->_fileHandle, $length)) != false ) {
+        while ($length > 0 && !feof($this->_fileHandle)) {
+            $nextBlock = fread($this->_fileHandle, $length);
+            if ($nextBlock === false) {
+                require_once 'Zend/Search/Lucene/Exception.php';
+                throw new Zend_Search_Lucene_Exception( "Error occured while file reading." );
+            }
+
             $data .= $nextBlock;
             $length -= strlen($nextBlock);
         }
+        if ($length != 0) {
+            require_once 'Zend/Search/Lucene/Exception.php';
+            throw new Zend_Search_Lucene_Exception( "Error occured while file reading." );
+        }
+
         return $data;
     }