Issues

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

Issue Type: Bug Created: 2008-10-14T13:52:27.000+0000 Last Updated: 2008-11-13T14:10:31.000+0000 Status: Resolved Fix version(s): - 1.7.0 (17/Nov/08)

Reporter: l c (cromulent) Assignee: Thomas Weidner (thomas) Tags: - Zend_File_Transfer

Related issues: Attachments:

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

<pre class="highlight">
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

<pre class="highlight">
        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

Posted by Thomas Weidner (thomas) on 2008-10-15T07:26:58.000+0000

Yes, this is true. Fixed in r11963.

Posted by Wil Sinclair (wil) on 2008-11-13T14:10:31.000+0000

Changing issues in preparation for the 1.7.0 release.

Have you found an issue?

See the Overview section for more details.

Copyright

© 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.

Contacts