question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug in Image.get_rendition() overwrites thumbnails of other images with similar prefix

See original GitHub issue

We’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:open
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
gasmancommented, Dec 7, 2016

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.

0reactions
gasmancommented, May 4, 2018

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).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Serious performance issues in 12.2 (AWS S3) #351 - GitHub
Hello, There is a serious performance issue in current 12.2 branch. Problem is that we have ~2M thumbnails, so if execution goes here...
Read more >
DayOne Users: There's a bug that replaces all your entry ...
I was looking through some old entries in DayOne when I noticed all my photos were quite pixelated, and in the corner of...
Read more >
Cloud function generating thumbnails doesn't overwrite old ...
I'm using cloud functions to resize and generate thumbnails for uploaded images in Firebase Storage. On the first upload the thumbnails are ...
Read more >
Thumbnails Cropping Even Though They Have Been Set To ...
Hi. We have a website that uses the nextgen plugin to display galleries. A problem has recently arisen after a plugin update whereby...
Read more >
Trying to add item (jpg image) with thumbnail usin...
I am adding multiple images (jpg format) to ArcGIS Portal using ... of the code that works (except 'overwrite' parameter) looks like that:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found