Skip to content
Snippets Groups Projects
Commit a68f7e6e authored by Nans Lefebvre's avatar Nans Lefebvre
Browse files

[FIX] ir_http: return a 404 if binary content cannot be decoded


Commit 5a9e1af6 has the unfortunate side-effect of crashing early
if for any reason the content cannot be decoded.
However, simply ignoring that the content cannot be decoded is no better idea:
some functions pipe the result to decoding functions that crash the same.
The resulting traceback pollutes the log with uninformative message such as:
binascii.Error: Incorrect padding 5 0.002 0.016

In case the content cannot be decoded (data corruption, or simply missing file)
we return a clean 404 instead, which is morally almost equivalent,
and is clean even from functions that depend on binary_content.

opw 2072586

closes odoo/odoo#38261

Signed-off-by: default avatarNans Lefebvre (len) <len@odoo.com>
parent b50bccb2
No related branches found
No related tags found
No related merge requests found
......@@ -380,7 +380,11 @@ class IrHttp(models.AbstractModel):
filename = "%s-%s-%s" % (record._name, record.id, field)
if not mimetype:
mimetype = guess_mimetype(base64.b64decode(content), default=default_mimetype)
try:
decoded_content = base64.b64decode(content)
except base64.binascii.Error: # if we could not decode it, no need to pass it down: it would crash elsewhere...
return (404, [], None)
mimetype = guess_mimetype(decoded_content, default=default_mimetype)
# extension
_, existing_extension = os.path.splitext(filename)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment