From 5156b220724692216345700cde08e4efb9edc49f Mon Sep 17 00:00:00 2001 From: Saurabh Choraria Date: Tue, 30 May 2023 06:58:59 +0000 Subject: [PATCH] [FIX] base_import: prevent traceback if image data contains non ASCII characters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When user tries to add non ascii characters in image field column in a file and then when he tries to import it the error will occur. Steps to reproduce: 1. Install contacts 2. export a contact and keep image field in fields to export. 3. Now in that file change the image data and add non ASCII characters (for example: 'รด'). 4. Now try to import this file in contacts. 5. The error will occur. Applying this commit will fix this issue. Currently, a ValueError is raised when we give non-ascii characters as input. So I have reported an issue in python in which I have mentioned to edit the documentation to note that it may raise ValueError for non-ascii content, or to fix '_bytes_from_decode_data' function to raise binascii.Error instead of ValueError. To track the issue - https://github.com/python/cpython/issues/105193 sentry-4029823200 closes odoo/odoo#123572 X-original-commit: ceb67160e1747f0a886efb8ca0a60499e2b080d1 Signed-off-by: Xavier Morel (xmo) --- addons/base_import/models/base_import.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/base_import/models/base_import.py b/addons/base_import/models/base_import.py index 8d85266ed60..1dce1e4d36e 100644 --- a/addons/base_import/models/base_import.py +++ b/addons/base_import/models/base_import.py @@ -1184,7 +1184,7 @@ class Import(models.TransientModel): else: try: base64.b64decode(line[index], validate=True) - except binascii.Error: + except ValueError: raise ImportValidationError( _("Found invalid image data, images should be imported as either URLs or base64-encoded data."), field=name, field_type=field['type']