Skip to content
Snippets Groups Projects
Commit 1b44748c authored by joda-odoo's avatar joda-odoo
Browse files

[FIX] tools: avoid crashes if expression is too large


When passing a very large expression to `literal_eval`, the odoo server crashes.
To avoid this behavior, a limit needs to be set by using the env varaible `ODOO_LIMIT_LITEVAL_BUFFER`.
If the variable is not set, it defaults to 100Kib.

closes odoo/odoo#121530

Signed-off-by: default avatarVranckx Florian (flvr) <flvr@odoo.com>
parent eda9ad14
No related branches found
No related tags found
No related merge requests found
import ast
import os
from shutil import copyfileobj from shutil import copyfileobj
from werkzeug.datastructures import FileStorage from werkzeug.datastructures import FileStorage
...@@ -22,3 +24,17 @@ else: ...@@ -22,3 +24,17 @@ else:
xlsx.Element_has_iter = True xlsx.Element_has_iter = True
FileStorage.save = lambda self, dst, buffer_size=1<<20: copyfileobj(self.stream, dst, buffer_size) FileStorage.save = lambda self, dst, buffer_size=1<<20: copyfileobj(self.stream, dst, buffer_size)
orig_literal_eval = ast.literal_eval
def literal_eval(expr):
# limit the size of the expression to avoid segmentation faults
# the default limit is set to 100KiB
# can be overridden by setting the ODOO_LIMIT_LITEVAL_BUFFER environment variable
buffer_size = os.getenv("ODOO_LIMIT_LITEVAL_BUFFER") or 1.024e5
if len(expr) > int(buffer_size):
raise ValueError("expression can't exceed buffer limit")
return orig_literal_eval(expr)
ast.literal_eval = literal_eval
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