details: https://code.tryton.org/tryton/commit/d9b8a4f37910
branch: 7.8
user: Cédric Krier <[email protected]>
date: Sat Nov 21 18:13:00 2026 +0100
description:
Limit the decompressed size of request
Closes #15257
(grafted from e592ed66d339edf8ff2d6d970ab08ea74a0f524b)
diffstat:
trytond/CHANGELOG | 1 +
trytond/trytond/protocols/wrappers.py | 13 ++++++++-----
2 files changed, 9 insertions(+), 5 deletions(-)
diffs (45 lines):
diff -r 262334e17d2c -r d9b8a4f37910 trytond/CHANGELOG
--- a/trytond/CHANGELOG Sat Nov 21 15:24:53 2026 +0100
+++ b/trytond/CHANGELOG Sat Nov 21 18:13:00 2026 +0100
@@ -1,3 +1,4 @@
+* Limit the decompressed size of request (issue15257)
* Define the forbidden fields that cannot be set as preferences (issue15256)
Version 7.8.20 - 2026-11-06
diff -r 262334e17d2c -r d9b8a4f37910 trytond/trytond/protocols/wrappers.py
--- a/trytond/trytond/protocols/wrappers.py Sat Nov 21 15:24:53 2026 +0100
+++ b/trytond/trytond/protocols/wrappers.py Sat Nov 21 18:13:00 2026 +0100
@@ -2,6 +2,7 @@
# this repository contains the full copyright notices and license terms.
import base64
import gzip
+import io
import logging
import time
import zlib
@@ -14,7 +15,7 @@
from werkzeug import exceptions
from werkzeug.datastructures import Authorization
-from werkzeug.exceptions import abort
+from werkzeug.exceptions import RequestEntityTooLarge, abort
from werkzeug.utils import redirect, send_file
from werkzeug.wrappers import Request as _Request
from werkzeug.wrappers import Response
@@ -72,10 +73,12 @@
@property
def decoded_data(self):
if self.content_encoding == 'gzip':
- if self.user_id:
- return gzip.decompress(self.data)
- else:
- abort(HTTPStatus.UNSUPPORTED_MEDIA_TYPE)
+ with gzip.GzipFile(
+ fileobj=io.BytesIO(self.data), mode='rb') as stream:
+ data = stream.read(self.max_content_length + 1)
+ if len(data) > self.max_content_length:
+ raise RequestEntityTooLarge()
+ return data
else:
return self.data