ZF-4597: Zend_File_Transfer receive method returns true in cases where Rename filter fails

Description

The _filter function inside of Zend/File/Transfer/Adapter/Abstract.php performs a try/catch block to detect errors. The problem is that the Rename filter uses the rename function which does not throw an exception upon failure. Instead, it only returns a boolean of false.

Because the Rename filter is meant to be used the Zend_File_Transfer to modify the destination directory of the file upload, you will get a boolean of true from calling the receive() method of the adapter when the rename is never successful. If a rename fails in this case, the file is never moved to it's final destination and receive() should return false.

One potential fix would be to update the Rename filter to throw an exception when the rename fails. Right now an exception is only being thrown if the file exists. Because the _filter method is checking for exceptions to detect errors, this rename failure never propagates up to _filter.

Zend/File/Transfer/Adapter/Abstract.php


protected function _filter($files = null)
    {
        $check           = $this->_getFiles($files);
        foreach ($check as $name => $content) {
            if (array_key_exists('filters', $content)) {
                foreach ($content['filters'] as $class) {
                    $filter = $this->_filters[$class];
                    try {
                        $result = $filter->filter($this->getFileName($name));

                        $this->_files[$name]['destination'] = dirname($result);
                        $this->_files[$name]['name']        = basename($result);
                    } catch (Zend_Filter_Exception $e) {
                        $this->_messages += array($e->getMessage());
                    }
                }
            }
        }

        if (count($this->_messages) > 0) {
            return false;
        }

        return true;
    }

Zend/Filter/File/Rename.php


        if (file_exists($newfile)) {
            require_once 'Zend/Filter/Exception.php';
            throw new Zend_Filter_Exception("File $value could not be renamed. It already exists.");
        }

        $result = rename($value, $newfile);

        if ($result === true) {
            return $newfile;
        }

        return false;

Comments

Yes, this is true. Fixed in r11963.

Changing issues in preparation for the 1.7.0 release.