Menu

#23 Image cache bug

open
nobody
None
5
2007-06-04
2007-06-04
No

The function clear in image_cache unlinks the images in the tmp directory but doesn't clear the cache array.

If you use dompdf in one php page more then once and those documents contain the same image then only the first will contain the image. I fixed it by clearing the array:

static function clear() {
if ( count(self::$_cache) ) {
foreach (self::$_cache as $entry) {
list($file, $ext) = $entry;
unlink($file);
}
self::$_cache=array();
}
}

Discussion

  • Nobody/Anonymous

    Logged In: NO

    Damn, just found the same bug and came here to submit the diff. He's mine anyway cause it's already in the clipboard:
    Index: include/image_cache.cls.php
    ===================================================================
    RCS file: /cvsroot/dompdf/dompdf/include/image_cache.cls.php,v
    retrieving revision 1.8
    diff -u -r1.8 image_cache.cls.php
    --- include/image_cache.cls.php 2 Aug 2006 18:44:25 -0000 1.8
    +++ include/image_cache.cls.php 1 Sep 2007 06:33:01 -0000
    @@ -147,7 +147,8 @@
    */
    static function clear() {
    if ( count(self::$_cache) ) {
    - foreach (self::$_cache as $entry) {
    + foreach (self::$_cache as $key => $entry) {
    + unset(self::$_cache[$key]);
    list($file, $ext) = $entry;
    unlink($file);
    }

     
  • Brian Sweeney

    Brian Sweeney - 2009-04-07

    I also have recently run into this bug. In the interest of encouraging discussion on how best to optimize the code I'll provide my change as well. No diff on my part, though, just the code:

    static function clear() {
    if ( count(self::$_cache) ) {
    while ($entry = array_shift(self::$_cache)) {
    list($file, $ext) = $entry;
    unlink($file);
    }
    }
    }

     

Log in to post a comment.