mirror of
https://github.com/kd2org/picodav.git
synced 2024-11-16 16:48:26 +01:00
Fix bug #6 by throwing error if FPM is used with Transfer-Encoding: chunked and the file is empty
FossilOrigin-Name: 85916dc58f18a0c17302c396345fbc9707a48a7c8a7b6b29c70bccb9bb35f02e
This commit is contained in:
parent
0400c84337
commit
381e8b2f71
2 changed files with 26 additions and 9 deletions
29
index.php
29
index.php
|
@ -235,7 +235,24 @@ namespace KD2\WebDAV
|
||||||
|
|
||||||
$this->extendExecutionTime();
|
$this->extendExecutionTime();
|
||||||
|
|
||||||
$created = $this->storage->put($uri, fopen('php://input', 'r'), $hash_algo, $hash, $mtime);
|
$stream = fopen('php://input', 'r');
|
||||||
|
|
||||||
|
// mod_fcgid <= 2.3.9 doesn't handle chunked transfer encoding for PUT requests
|
||||||
|
// see https://github.com/kd2org/picodav/issues/6
|
||||||
|
if (strstr($_SERVER['HTTP_TRANSFER_ENCODING'] ?? '', 'chunked') && PHP_SAPI == 'fpm-fcgi') {
|
||||||
|
// We can't seek here
|
||||||
|
// see https://github.com/php/php-src/issues/9441
|
||||||
|
$l = strlen(fread($stream, 1));
|
||||||
|
|
||||||
|
if ($l === 0) {
|
||||||
|
throw new Exception('This server cannot accept "Transfer-Encoding: chunked" uploads (please upgrade to mod_fcgid >= 2.3.10).', 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
// reset stream
|
||||||
|
fseek($stream, 0, SEEK_SET);
|
||||||
|
}
|
||||||
|
|
||||||
|
$created = $this->storage->put($uri, $stream, $hash_algo, $hash, $mtime);
|
||||||
|
|
||||||
$prop = $this->storage->properties($uri, ['DAV::getetag'], 0);
|
$prop = $this->storage->properties($uri, ['DAV::getetag'], 0);
|
||||||
|
|
||||||
|
@ -1639,7 +1656,7 @@ namespace PicoDAV
|
||||||
|
|
||||||
if ($delete) {
|
if ($delete) {
|
||||||
@unlink($tmp_file);
|
@unlink($tmp_file);
|
||||||
throw new WebDAV_Exception('Your quota is exhausted', 403);
|
throw new WebDAV_Exception('Your quota is exhausted', 507);
|
||||||
}
|
}
|
||||||
elseif ($hash && $hash_algo == 'MD5' && md5_file($tmp_file) != $hash) {
|
elseif ($hash && $hash_algo == 'MD5' && md5_file($tmp_file) != $hash) {
|
||||||
@unlink($tmp_file);
|
@unlink($tmp_file);
|
||||||
|
@ -1718,7 +1735,7 @@ namespace PicoDAV
|
||||||
$quota = disk_free_space($this->path);
|
$quota = disk_free_space($this->path);
|
||||||
|
|
||||||
if (filesize($source) > $quota) {
|
if (filesize($source) > $quota) {
|
||||||
throw new WebDAV_Exception('Your quota is exhausted', 403);
|
throw new WebDAV_Exception('Your quota is exhausted', 507);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1766,7 +1783,7 @@ namespace PicoDAV
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!disk_free_space($this->path)) {
|
if (!disk_free_space($this->path)) {
|
||||||
throw new WebDAV_Exception('Your quota is exhausted', 403);
|
throw new WebDAV_Exception('Your quota is exhausted', 507);
|
||||||
}
|
}
|
||||||
|
|
||||||
$target = $this->path . $uri;
|
$target = $this->path . $uri;
|
||||||
|
@ -1923,11 +1940,11 @@ RewriteRule ^.*$ /index.php [END]
|
||||||
$fp = fopen(__FILE__, 'r');
|
$fp = fopen(__FILE__, 'r');
|
||||||
|
|
||||||
if ($relative_uri == '.webdav/webdav.js') {
|
if ($relative_uri == '.webdav/webdav.js') {
|
||||||
fseek($fp, 52012, SEEK_SET);
|
fseek($fp, 52608, SEEK_SET);
|
||||||
echo fread($fp, 27789);
|
echo fread($fp, 27789);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fseek($fp, 52012 + 27789, SEEK_SET);
|
fseek($fp, 52608 + 27789, SEEK_SET);
|
||||||
echo fread($fp, 7004);
|
echo fread($fp, 7004);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -332,7 +332,7 @@ namespace PicoDAV
|
||||||
|
|
||||||
if ($delete) {
|
if ($delete) {
|
||||||
@unlink($tmp_file);
|
@unlink($tmp_file);
|
||||||
throw new WebDAV_Exception('Your quota is exhausted', 403);
|
throw new WebDAV_Exception('Your quota is exhausted', 507);
|
||||||
}
|
}
|
||||||
elseif ($hash && $hash_algo == 'MD5' && md5_file($tmp_file) != $hash) {
|
elseif ($hash && $hash_algo == 'MD5' && md5_file($tmp_file) != $hash) {
|
||||||
@unlink($tmp_file);
|
@unlink($tmp_file);
|
||||||
|
@ -411,7 +411,7 @@ namespace PicoDAV
|
||||||
$quota = disk_free_space($this->path);
|
$quota = disk_free_space($this->path);
|
||||||
|
|
||||||
if (filesize($source) > $quota) {
|
if (filesize($source) > $quota) {
|
||||||
throw new WebDAV_Exception('Your quota is exhausted', 403);
|
throw new WebDAV_Exception('Your quota is exhausted', 507);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -459,7 +459,7 @@ namespace PicoDAV
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!disk_free_space($this->path)) {
|
if (!disk_free_space($this->path)) {
|
||||||
throw new WebDAV_Exception('Your quota is exhausted', 403);
|
throw new WebDAV_Exception('Your quota is exhausted', 507);
|
||||||
}
|
}
|
||||||
|
|
||||||
$target = $this->path . $uri;
|
$target = $this->path . $uri;
|
||||||
|
|
Loading…
Reference in a new issue