[FIX] P3: resizing of image *fields*

Fields sent from the client are pretty much always *text*. This can be
problematic for image fields sent as base64 *text* as in Python 3 the
base64 routines only work between bytes.

Alter the core field-resizing function (image_get_resized_images) such
that it ensures text base64 sources are encoded back to bytes before
being forwarded to the main resizing routines (which I don't think
should deal with *that* issue).

Fixes #18985: error when trying to update a company's logo
This commit is contained in:
Xavier Morel
2017-09-07 10:47:02 +02:00
parent 9dff6516e4
commit 6bb6944e6b
+4
View File
@@ -9,6 +9,8 @@ from PIL import ImageEnhance
from random import randrange
# Preload PIL with the minimal subset of image formats we need
from odoo.tools import pycompat
Image.preinit()
Image._initialized = 2
@@ -253,6 +255,8 @@ def image_get_resized_images(base64_source, return_big=False, return_medium=True
previous parameters.
"""
return_dict = dict()
if isinstance(base64_source, pycompat.text_type):
base64_source = base64_source.encode('ascii')
if return_big:
return_dict[big_name] = image_resize_image_big(base64_source, avoid_if_small=avoid_resize_big)
if return_medium: