Make sure we only use numbers as length

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2016-10-14 09:09:21 +02:00
parent 09fbe32d48
commit 1a104df189
No known key found for this signature in database
GPG Key ID: E166FD8976B3BAC8
2 changed files with 9 additions and 2 deletions

View File

@ -120,12 +120,13 @@ class QuotaPlugin extends \Sabre\DAV\ServerPlugin {
public function getLength() {
$req = $this->server->httpRequest;
$length = $req->getHeader('X-Expected-Entity-Length');
if (!$length) {
if (!is_numeric($length)) {
$length = $req->getHeader('Content-Length');
$length = is_numeric($length) ? $length : null;
}
$ocLength = $req->getHeader('OC-Total-Length');
if ($length && $ocLength) {
if (is_numeric($length) && is_numeric($ocLength)) {
return max($length, $ocLength);
}

View File

@ -132,6 +132,12 @@ class QuotaPluginTest extends \Test\TestCase {
array(512, array('CONTENT-LENGTH' => '512')),
array(2048, array('OC-TOTAL-LENGTH' => '2048', 'CONTENT-LENGTH' => '1024')),
array(4096, array('OC-TOTAL-LENGTH' => '2048', 'X-EXPECTED-ENTITY-LENGTH' => '4096')),
[null, ['X-EXPECTED-ENTITY-LENGTH' => 'A']],
[null, ['CONTENT-LENGTH' => 'A']],
[1024, ['OC-TOTAL-LENGTH' => 'A', 'CONTENT-LENGTH' => '1024']],
[1024, ['OC-TOTAL-LENGTH' => 'A', 'X-EXPECTED-ENTITY-LENGTH' => '1024']],
[null, ['OC-TOTAL-LENGTH' => '2048', 'X-EXPECTED-ENTITY-LENGTH' => 'A']],
[null, ['OC-TOTAL-LENGTH' => '2048', 'CONTENT-LENGTH' => 'A']],
);
}