From 62b731a3b8937d08cdbb1f9e6cac4c4388880766 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 14 Jan 2022 14:26:33 +0000 Subject: [PATCH] [FIX] core: possibility of allocation error in native magic libraries Both of the native `magic` libraries can trigger an allocation error if the buffer being sniffed is large. This results in nothing useful for the user and just triggers and exception when trying to create large attachments (in the hundreds of MBs). Fix by implementing the workaround suggested in ahupp/python-magic#82, under the assumption that it should also work fine for Debian's python-magic. The pure-python trivial version of odoo should not have this issue, as it does not normally copy the source buffer in full, it just seeks and slices the buffer, and occasionally parses it as a zip (but does not normally load everything in memory). Task-2722110 closes odoo/odoo#83190 X-original-commit: 94fc66452f28a8c64b4077d6cc2dd17ea1f00aa6 Signed-off-by: Xavier Morel (xmo) --- odoo/tools/mimetypes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/odoo/tools/mimetypes.py b/odoo/tools/mimetypes.py index 3c30b3ace83..14a0099bd98 100644 --- a/odoo/tools/mimetypes.py +++ b/odoo/tools/mimetypes.py @@ -180,7 +180,7 @@ if magic: _guesser = ms.buffer def guess_mimetype(bin_data, default=None): - mimetype = _guesser(bin_data) + mimetype = _guesser(bin_data[:1024]) # upgrade incorrect mimetype to official one, fixed upstream # https://github.com/file/file/commit/1a08bb5c235700ba623ffa6f3c95938fe295b262 if mimetype == 'image/svg':