Skip to content

[Bug] phpThumbOf + getResources/MIGX #48

Open

Description

@wm-simon

If you use the same filename in different paths phpThumbOf will output the same file.

Resource 1:
Filepath original: img/resrouce-1/file.jpg
Filepath phpThumbOf: /assets/components/phpthumbof/cache/file.hash.jpg

Resource 2:
Filepath original: img/resrouce-2/file.jpg
Filepath phpThumbOf: /assets/components/phpthumbof/cache/file.hash.jpg

phpThumbOf uses the same file for both resources, because the path is not considered.

Activity

  1. mburtscher commented on Jan 28, 2013

    @mburtscher

    This seems to be a new bug! We hadn't had this issue before.

    Using modx 2.2.6-pl and phpthumbof 1.4.0

  2. oo12 commented on Feb 26, 2013

    @oo12

    Quick fix: set phpthumbof.hash_thumbnail_names to Yes in System Settings.

    If you have this turned off (the default) so your filenames are in this format file_name.options_hash.file_extension (for example: slide1.17257f7f69358c7cfb0c8d1dd1b859a014.jpg ) then the way phpthumbof generates filenames creates two potential problems.

    1. the one you mentioned: same base filename + same phpthumb options + same resource + different paths = same output filename.
    2. there's another problem too: same path + same base filename + same phpthumb options + different resource = different output filenames.

    I have a site with a few hundred pages, and many of those pages use the same 4 images for one part (sized by phpthumbof). I happened to look in phpthumbof's cache and was surprised to find thousands of versions of the same 4 files!

    I tracked it down to line 306 in core/components/phpthumbof/model/phpthumbof/phpthumbof.class.php:

    $this->cacheFilename .= '.'.md5(serialize($this->options)).$this->modx->resource->get('id');
    

    $this->cacheFilename is the base name of the file (so 'slide1' in the example above). You can see what's going wrong. Seems a better way to do it would be this:

     $this->cacheFilename .= '.' . md5( serialize($this->options) . pathinfo($inputSanitized, PATHINFO_DIRNAME) );
    

    I think that will fix both your problem and mine. That changes the "equations" above to:

    1. same base filename + same phpthumb options + same resource + different paths = different output filenames
    2. same path + same base filename + same phpthumb options + different resource = same output filename

    Or am I missing something? If hash collisions are a problem with the extra data in there, switching to sha1–only marginally slower than md5–would probably solve it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions