Issues

ZF-10006: Zend_Captcha_Image::_gc() does not consider file suffix

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());
+                    }
                 }
             }
         }

Comments

The same patcha provide in the bug description

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

Thanks :-)