From 6bb6944e6b8bce7c50ee46c1350f3c70012cd476 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 7 Sep 2017 10:47:02 +0200 Subject: [PATCH] [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 --- odoo/tools/image.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/odoo/tools/image.py b/odoo/tools/image.py index 0f830b0924c..e81307ed8a9 100644 --- a/odoo/tools/image.py +++ b/odoo/tools/image.py @@ -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: