details:   https://code.tryton.org/tryton/commit/24b5210b5924
branch:    8.0
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 91bbfe4bf662 -r 24b5210b5924 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 8.0.14 - 2026-11-06
diff -r 91bbfe4bf662 -r 24b5210b5924 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
@@ -3,6 +3,7 @@
 import base64
 import collections
 import gzip
+import io
 import logging
 import time
 import zlib
@@ -15,7 +16,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 BaseRequest
 from werkzeug.wrappers import Response as BaseResponse
@@ -113,10 +114,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
 

Reply via email to