Bug in Image.get_rendition() overwrites thumbnails of other images with similar prefix
See original GitHub issueWe’ve noticed that wagtailimages overwrites thumbnails of previous image versions, when they have a similar prefix. Depending on the filter settings, this may happen after 17 similar characters.
You can test this by running the Image.get_rendition()
function with an image that has a similar prefix. In the debugger, we found that the following values are constructed in AbstractImage.get_rendition()
:
spec = 'fill-720x720-c100|format-jpeg'
input_filename = 'our-story-verhaal-3.jpg'
cache_key = '2e16d0ba' # the result of sha1('None-None-None-None').hexdigest()[:8]
then the magic bug happens at https://github.com/torchbox/wagtail/blob/2c9805dc3fa37e9bf27fc7593de4465673faffca/wagtail/wagtailimages/models.py#L301:
output_filename_without_extension = input_filename_without_extension[:(59 - len(output_extension))]
Which produces:
output_filename_without_extension = 'our-story-verhaal' # <-- SILENT TRUNCATION!!
output_filename = 'our-story-verhaal.2e16d0ba.fill-720x720-c100.format-jpeg.jpg'
Which means that any previous image that starts with the same 17 characters (“our-story-verhaal”) is overwritten with thumbnails of the next image. In our case for example, the tester uploaded 3 images:
- our-story-verhaal-1.jpg
- our-story-verhaal-2.jpg
- our-story-verhaal-3.jpg
In the end, all images had the same thumbnail.
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
Sounds good to me. While I personally think it would be nice for django-storages to not blatantly violate the Django storages spec… hashing on file content would be a quick and effective way to solve this and several other problems in one go (including the far-future caching).
I think it would make sense to drop the filter-spec bit of the filename at the same time - that was originally put in place in the hopes that we could keep the filenames somewhat meaningful, but that’s a fairly marginal benefit and probably incompatible with far-future expiry.
See #4502 -
S3BotoStorage
’s failure to handle duplicate filenames also breaks documents (and so any workaround we apply should probably also be applied to documents).