ZF-3757: Bug in constructor method of the Zend_Validate_File_Size class

Issue Type: Bug Created: 2008-07-25T06:40:45.000+0000 Last Updated: 2008-07-25T10:36:21.000+0000 Status: Resolved Fix version(s): - 1.5.3 (28/Jul/08)

Reporter: Hugo HAMON (emacs) Assignee: Thomas Weidner (thomas) Tags: - Zend_Validate

Related issues: Attachments:


When passing an array of min and max file sizes of the Zend_Validate_File_Size class, the max value is lost and a notice is raised. Below is the code I've tried :

$oFileTransfer = new Zend_File_Transfer_Adapter_Http(); $oFileTransfer ->addValidators('Size', array('min'=>'50kB','max'=>'5Mb'))->addValidators('Extension', 'png')->setDestination(dirname(FILE).'/uploads')->receive();

And below is the dump of my XDebug debug backtrace.

Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object in /home/noeweb5/communs/library/Zend/Validate/File/Size.php on line 96 Call Stack

Time Memory Function Location

1 0.0011 68608 {main}( ) ../upload.php:0 2 0.0736 2749728 Zend_File_Transfer_Adapter_Abstract->addValidators( ) ../upload.php:32 3 0.0752 2818228 Zend_Validate_File_Size->__construct( ) ../Abstract.php:140 4 0.0752 2818716 array_key_exists ( ) ../Size.php:96

The bug comes from here in the __construct() method of Zend_Validate_File_Size :

[l.91] if (array_key_exists('min', $min)) { $min = $min['min']; // Here $min is not an array anymore but a string value so the 'max' index doesn't exist anymore if (array_key_exists('max', $min)) { $max = $min['max']; } }

The way to fix it is to use a temporary array like this :

if (array_key_exists('min', $min)) { $tmp = $min; $min = $min['min']; // Here $min is not an array anymore but a string value so the 'max' index doesn't exist anymore if (array_key_exists('max', $tmp)) { $max = $tmp['max']; } unset($tmp); }


Posted by Hugo HAMON (emacs) on 2008-07-25T06:44:07.000+0000

I had the code I've tried.

Posted by Thomas Weidner (thomas) on 2008-07-25T10:33:17.000+0000

Solved with r10418.

Btw: Your patch is ineffective. A simple statement switch does the same and is faster. ;-)

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.