From 7e5251bdd8e424a438ba6e66d8c6b3e00c489e7e Mon Sep 17 00:00:00 2001 From: Younn Olivier Date: Mon, 10 May 2021 15:38:57 +0000 Subject: [PATCH] [FIX] web_editor: fix svg images upload We check if the mimetype is supported when uploading an image. task-2523574 closes odoo/odoo#71839 X-original-commit: 3765ac1f1f1644c919456246f1a3791c47c45a83 Signed-off-by: Quentin Smetz (qsm) --- addons/web_editor/controllers/main.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/addons/web_editor/controllers/main.py b/addons/web_editor/controllers/main.py index 63290d54224..5f2e714f5a8 100644 --- a/addons/web_editor/controllers/main.py +++ b/addons/web_editor/controllers/main.py @@ -18,6 +18,7 @@ from odoo.addons.http_routing.models.ir_http import slug, unslug from odoo.exceptions import UserError from odoo.modules.module import get_module_path, get_resource_path from odoo.tools.misc import file_open +from odoo.tools.mimetypes import guess_mimetype from ..models.ir_attachment import SUPPORTED_IMAGE_EXTENSIONS, SUPPORTED_IMAGE_MIMETYPES @@ -169,13 +170,9 @@ class Web_Editor(http.Controller): format_error_msg = _("Uploaded image's format is not supported. Try with: %s", ', '.join(SUPPORTED_IMAGE_EXTENSIONS)) try: data = tools.image_process(data, size=(width, height), quality=quality, verify_resolution=True) - img_extension = tools.base64_to_image(data).format.lower() - if img_extension not in [ext.replace('.', '') for ext in SUPPORTED_IMAGE_EXTENSIONS]: + mimetype = guess_mimetype(b64decode(data)) + if mimetype not in SUPPORTED_IMAGE_MIMETYPES: return {'error': format_error_msg} - except UserError: - # considered as an image by the brower file input, but not - # recognized as such by PIL, eg .webp - return {'error': format_error_msg} except ValueError as e: return {'error': e.args[0]}