mirror of
https://github.com/xroche/httrack.git
synced 2026-07-16 05:40:59 +03:00
Compare commits
3 Commits
codeql-ign
...
fix-chunke
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
95c7d3c044 | ||
|
|
755481e33b | ||
|
|
83a3af7fc5 |
@@ -3310,16 +3310,26 @@ void back_wait(struct_back * sback, httrackp * opt, cache_back * cache,
|
||||
back[i].chunk_blocksize = -1; /* ending */
|
||||
back[i].r.totalsize += chunk_size; // noter taille
|
||||
if (back[i].r.adr != NULL || !back[i].r.is_write) { // Not to disk
|
||||
back[i].r.adr =
|
||||
(char *) realloct(back[i].r.adr,
|
||||
(size_t) back[i].r.totalsize + 1);
|
||||
if (!back[i].r.adr) {
|
||||
if (cache->log != NULL) {
|
||||
hts_log_print(opt, LOG_ERROR,
|
||||
"not enough memory (" LLintP
|
||||
") for %s%s",
|
||||
(LLint) back[i].r.totalsize,
|
||||
back[i].url_adr, back[i].url_fil);
|
||||
// totalsize sums attacker-declared chunk sizes; past
|
||||
// 2GB the (size_t) cast below truncates on 32-bit and
|
||||
// under-allocates. Mark the chunk invalid so the shared
|
||||
// error path tears the transfer down.
|
||||
if (back[i].r.totalsize > INT32_MAX) {
|
||||
hts_log_print(opt, LOG_WARNING,
|
||||
"Chunked resource too large for %s%s",
|
||||
back[i].url_adr, back[i].url_fil);
|
||||
chunk_size = -1;
|
||||
} else {
|
||||
back[i].r.adr = (char *) realloct(
|
||||
back[i].r.adr, (size_t) back[i].r.totalsize + 1);
|
||||
if (!back[i].r.adr) {
|
||||
if (cache->log != NULL) {
|
||||
hts_log_print(opt, LOG_ERROR,
|
||||
"not enough memory (" LLintP
|
||||
") for %s%s",
|
||||
(LLint) back[i].r.totalsize,
|
||||
back[i].url_adr, back[i].url_fil);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
18
tests/55_local-chunked.test
Executable file
18
tests/55_local-chunked.test
Executable file
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
# A well-formed Transfer-Encoding: chunked response mirrors intact: the chunk
|
||||
# automaton (htsback.c) joins the bodies and the 2GB in-RAM cap stays quiet.
|
||||
# The 76-char run spans a 64-byte chunk boundary (only contiguous once joined);
|
||||
# a CR anywhere would be leftover framing; '</body>' proves no truncation.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
: "${top_srcdir:=..}"
|
||||
|
||||
bash "$top_srcdir/tests/local-crawl.sh" --errors 0 \
|
||||
--found 'chunked/page.html' \
|
||||
--file-matches 'chunked/page.html' \
|
||||
'chunk-body chunk-body chunk-body chunk-body chunk-body chunk-body chunk-body' \
|
||||
--file-matches 'chunked/page.html' '</body>' \
|
||||
--file-not-matches 'chunked/page.html' $'\r' \
|
||||
--log-not-found 'too large' \
|
||||
httrack 'BASEURL/chunked/index.html'
|
||||
@@ -131,6 +131,7 @@ TESTS = \
|
||||
51_local-update-codec.test \
|
||||
52_local-socks5.test \
|
||||
53_local-proxytrack-cache-corrupt.test \
|
||||
54_local-update-truncate-purge.test
|
||||
54_local-update-truncate-purge.test \
|
||||
55_local-chunked.test
|
||||
|
||||
CLEANFILES = check-network_sh.cache
|
||||
|
||||
@@ -1215,6 +1215,28 @@ class Handler(SimpleHTTPRequestHandler):
|
||||
if self.command != "HEAD":
|
||||
self.wfile.write(body)
|
||||
|
||||
def route_chunked_index(self):
|
||||
self.send_html('\t<a href="page.html">chunked</a>\n')
|
||||
|
||||
def route_chunked_page(self):
|
||||
# Transfer-Encoding: chunked over many small chunks: drives the engine's
|
||||
# chunk automaton (htsback.c). The mirrored file must equal the joined
|
||||
# chunk bodies, so the 2GB in-RAM cap doesn't fire on ordinary traffic.
|
||||
blob = big_html("chunked", "<p>" + "chunk-body " * 300 + "</p>")
|
||||
self.protocol_version = "HTTP/1.1"
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "text/html; charset=utf-8")
|
||||
self.send_header("Transfer-Encoding", "chunked")
|
||||
self.send_header("Connection", "close")
|
||||
self.end_headers()
|
||||
if self.command == "HEAD":
|
||||
return
|
||||
step = 64
|
||||
for off in range(0, len(blob), step):
|
||||
piece = blob[off : off + step]
|
||||
self.wfile.write(b"%X\r\n" % len(piece) + piece + b"\r\n")
|
||||
self.wfile.write(b"0\r\n\r\n")
|
||||
|
||||
# Content-Disposition naming: the attachment filename replaces the
|
||||
# URL-derived name; path components in it are stripped (RFC 2616).
|
||||
CDISPO_NAMES = {
|
||||
@@ -1554,6 +1576,8 @@ class Handler(SimpleHTTPRequestHandler):
|
||||
"/crange206mem/blob.bin": route_crange206mem,
|
||||
"/size/index.html": route_size_index,
|
||||
"/size/oversize.bin": route_size_oversize,
|
||||
"/chunked/index.html": route_chunked_index,
|
||||
"/chunked/page.html": route_chunked_page,
|
||||
"/errpage/index.html": route_errpage_index,
|
||||
"/errpage/good.html": route_errpage_good,
|
||||
"/errpage/missing.html": route_errpage_missing,
|
||||
|
||||
Reference in New Issue
Block a user