Skip to content

Commit 1562047

Browse files
committed
[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#83180 X-original-commit: 94fc664 Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
1 parent 0112d69 commit 1562047

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

odoo/tools/mimetypes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def _odoo_guess_mimetype(bin_data, default='application/octet-stream'):
180180
_guesser = ms.buffer
181181

182182
def guess_mimetype(bin_data, default=None):
183-
mimetype = _guesser(bin_data)
183+
mimetype = _guesser(bin_data[:1024])
184184
# upgrade incorrect mimetype to official one, fixed upstream
185185
# https://github.com/file/file/commit/1a08bb5c235700ba623ffa6f3c95938fe295b262
186186
if mimetype == 'image/svg':

0 commit comments

Comments
 (0)