1
0
Fork 0

do not retrieve content if it's too large

pull/744/head
Robert Lu 2019-05-21 18:16:50 +08:00
parent 9dc1656592
commit b210c37d57
2 changed files with 9 additions and 7 deletions

View File

@ -3,6 +3,7 @@ declare(strict_types = 1);
namespace LanguageServer\ContentRetriever;
use LanguageServer\ContentTooLargeException;
use Sabre\Event\Promise;
use function LanguageServer\uriToPath;
@ -19,6 +20,13 @@ class FileSystemContentRetriever implements ContentRetriever
*/
public function retrieve(string $uri): Promise
{
return Promise\resolve(file_get_contents(uriToPath($uri)));
$limit = 150000;
$path = uriToPath($uri);
$size = filesize($path);
if ($size > $limit) {
return Promise\reject(new ContentTooLargeException($uri, $size, $limit));
}
return Promise\resolve(file_get_contents($path));
}
}

View File

@ -105,13 +105,7 @@ class PhpDocumentLoader
public function load(string $uri): Promise
{
return coroutine(function () use ($uri) {
$limit = 150000;
$content = yield $this->contentRetriever->retrieve($uri);
$size = strlen($content);
if ($size > $limit) {
throw new ContentTooLargeException($uri, $size, $limit);
}
if (isset($this->documents[$uri])) {
$document = $this->documents[$uri];