mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2026-11-20 15:10:23 +00:00
Hardening Brotli/Zstandard decoding against hostile input
This commit is contained in:
parent
a4c983ae06
commit
5a5aebfc6e
4 changed files with 219 additions and 91 deletions
|
|
@ -325,9 +325,14 @@ def decodePage(page, contentEncoding, contentType, percentDecode=True):
|
|||
elif contentEncoding == "zstd":
|
||||
if _zstd is None:
|
||||
raise Exception("no Zstandard decoder available")
|
||||
page = _zstd.decompress(page)
|
||||
# bounded streaming decode: cap output at MAX_CONNECTION_TOTAL_SIZE without allocating the
|
||||
# full result first, and enforce the 8 MB window the HTTP 'zstd' coding mandates
|
||||
decompressor = _zstd.ZstdDecompressor(options={_zstd.DecompressionParameter.window_log_max: 23})
|
||||
page = decompressor.decompress(page, max_length=MAX_CONNECTION_TOTAL_SIZE + 1)
|
||||
if len(page) > MAX_CONNECTION_TOTAL_SIZE:
|
||||
raise Exception("size too large")
|
||||
if not decompressor.eof:
|
||||
raise Exception("incomplete Zstandard stream")
|
||||
else:
|
||||
data = gzip.GzipFile("", "rb", 9, io.BytesIO(page))
|
||||
page = data.read(MAX_CONNECTION_TOTAL_SIZE + 1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue