django-cms / django-filer

File and Image Management Application for django
https://django-filer.readthedocs.io/
Other
1.73k stars 575 forks source link

ZeroDivisionError when uploading SVG with no width and height (sprite SVG with hidden==true) #1287

Closed gonzalodelgado closed 1 year ago

gonzalodelgado commented 2 years ago

Hi there!

I'm getting a ZeroDivisionError from easy_thumbnails when uploading a SVG sprite that has no dimension attributes. ajax_upload (in clipboardadmin.py) tries to get a thumbnail, which ends up in a ZeroDivisionError when easy_thumbnail tries to scale and crop, here's the traceback:

Traceback (most recent call last):
  File "[virtualenv-path]/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "[virtualenv-path]/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "[virtualenv-path]/lib/python3.8/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "[virtualenv-path]/lib/python3.8/site-packages/filer/admin/clipboardadmin.py", line 132, in ajax_upload
    thumbnail_180 = file_obj.file.get_thumbnail(
  File "[virtualenv-path]/lib/python3.8/site-packages/easy_thumbnails/files.py", line 508, in get_thumbnail
    thumbnail = self.generate_thumbnail(
  File "[virtualenv-path]/lib/python3.8/site-packages/easy_thumbnails/files.py", line 389, in generate_thumbnail
    thumbnail_image = engine.process_image(image, thumbnail_options,
  File "[virtualenv-path]/lib/python3.8/site-packages/easy_thumbnails/engine.py", line 35, in process_image
    image = processor(image, **processor_options)
  File "[virtualenv-path]/lib/python3.8/site-packages/filer/thumbnail_processors.py", line 52, in scale_and_crop_with_subject_location
    return processors.scale_and_crop(im, size, zoom=zoom, crop=crop,
  File "[virtualenv-path]/lib/python3.8/site-packages/easy_thumbnails/processors.py", line 177, in scale_and_crop
    scale = max(target_x / source_x, target_y / source_y)
ZeroDivisionError: float division by zero

Here's a SVG file that triggers the error: https://d2lnf7sa75novz.cloudfront.net/filer_public/a0/0a/a00a2d61-063d-4b42-bd7b-e2cecc7ea274/events.svg

Not sure if this should be considered a filer or easy_thumbnails bug though.

jrief commented 2 years ago

Not sure if this should be considered a filer or easy_thumbnails bug though.

This definitely is an easy_thumbnails bug, so please open it there.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 1 year ago

This will now be closed due to inactivity, but feel free to reopen it.