Skip to content
Snippets Groups Projects
Commit 9ae1a5d1 authored by Andreas Gohr's avatar Andreas Gohr
Browse files

fix #2466. Avoid caching half fetched files

When a remote resource exceeds the fetchsize but the remote server does
not return a Content-Length, we read only the fetchsize amount of bytes
but failed to detect that this was a partial read, thus a partial
resource got cached.

This fix will read fetchsize+1, which will then be correctly determined
as too big and thrown away.
parent 30bea1b9
No related branches found
No related tags found
No related merge requests found
......@@ -434,14 +434,14 @@ class HTTPClient {
// read up to the content-length or max_bodysize
// for keep alive we need to read the whole message to clean up the socket for the next read
if(!$this->keep_alive && $this->max_bodysize && $this->max_bodysize < $this->resp_headers['content-length']){
$length = $this->max_bodysize;
$length = $this->max_bodysize+1;
}else{
$length = $this->resp_headers['content-length'];
}
$r_body = $this->_readData($socket, $length, 'response (content-length limited)', true);
}elseif( !isset($this->resp_headers['transfer-encoding']) && $this->max_bodysize && !$this->keep_alive){
$r_body = $this->_readData($socket, $this->max_bodysize, 'response (content-length limited)', true);
$r_body = $this->_readData($socket, $this->max_bodysize+1, 'response (content-length limited)', true);
} elseif ((int)$this->status === 204) {
// request has no content
} else{
......@@ -451,7 +451,7 @@ class HTTPClient {
}
}
// recheck body size, we might had to read the whole body, so we abort late or trim here
// recheck body size, we might have read max_bodysize+1 or even the whole body, so we abort late here
if($this->max_bodysize){
if(strlen($r_body) > $this->max_bodysize){
if ($this->max_bodysize_abort) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment