Zend Framework

Zend_Captcha_Image::_gc() does not consider file suffix

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.10.5
  • Fix Version/s: 1.10.7
  • Component/s: Zend_Captcha
  • Labels:
    None

Description

The garbage collector for Zend_Captcha_Image (Zend_Captcha_Image::_gc()) deletes all the files inside the directory used to store the captcha's images (including hidden files). This is a problem if you want to use a directory that is used by other parts of your application.

Bellow a patch that fix the issue. With this change the garbage collector will only delete files that match the suffix.

--- Image.php	2010-06-17 13:25:20.000000000 -0400
+++ Image.php	2010-06-17 13:25:16.000000000 -0400
@@ -580,7 +580,11 @@
         foreach (new DirectoryIterator($imgdir) as $file) {
             if (!$file->isDot() && !$file->isDir()) {
                 if ($file->getMTime() < $expire) {
-                    unlink($file->getPathname());
+                    $len = strlen($this->_suffix);
+                    // only deletes files ending with $this->_suffix
+                    if (substr($file->getFilename(), -($len), $len) == $this->_suffix) {
+                        unlink($file->getPathname());
+                    }
                 }
             }
         }

Activity

Hide
Rodrigo Primo added a comment -

The same patcha provide in the bug description

Show
Rodrigo Primo added a comment - The same patcha provide in the bug description
Hide
Mickael Perraud added a comment -

Fixed in trunk with r22589 and applied on 1.10 branch with r22590

Show
Mickael Perraud added a comment - Fixed in trunk with r22589 and applied on 1.10 branch with r22590
Hide
Rodrigo Primo added a comment -

Thanks

Show
Rodrigo Primo added a comment - Thanks

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: