Skip to content

Commit 5a5aebf

Browse files
committed
Hardening Brotli/Zstandard decoding against hostile input
1 parent a4c983a commit 5a5aebf

4 files changed

Lines changed: 222 additions & 94 deletions

File tree

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from thirdparty import six
2121

2222
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
23-
VERSION = "1.10.7.186"
23+
VERSION = "1.10.7.187"
2424
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2525
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2626
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

lib/request/basic.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,14 @@ def decodePage(page, contentEncoding, contentType, percentDecode=True):
325325
elif contentEncoding == "zstd":
326326
if _zstd is None:
327327
raise Exception("no Zstandard decoder available")
328-
page = _zstd.decompress(page)
328+
# bounded streaming decode: cap output at MAX_CONNECTION_TOTAL_SIZE without allocating the
329+
# full result first, and enforce the 8 MB window the HTTP 'zstd' coding mandates
330+
decompressor = _zstd.ZstdDecompressor(options={_zstd.DecompressionParameter.window_log_max: 23})
331+
page = decompressor.decompress(page, max_length=MAX_CONNECTION_TOTAL_SIZE + 1)
329332
if len(page) > MAX_CONNECTION_TOTAL_SIZE:
330333
raise Exception("size too large")
334+
if not decompressor.eof:
335+
raise Exception("incomplete Zstandard stream")
331336
else:
332337
data = gzip.GzipFile("", "rb", 9, io.BytesIO(page))
333338
page = data.read(MAX_CONNECTION_TOTAL_SIZE + 1)

0 commit comments

Comments
 (0)