From f3ad69181b8afed2c9edf7be5a2918144ff4ea32 Mon Sep 17 00:00:00 2001 From: Frank de Jonge Date: Wed, 23 Jun 2021 23:39:25 +0200 Subject: [PATCH] Reject paths with funky whitespace. --- .gitignore | 1 + src/CorruptedPathDetected.php | 17 +++++++++++++++++ src/Util.php | 19 ++++++++++--------- tests/UtilTests.php | 20 ++++++++++++++++++-- 4 files changed, 46 insertions(+), 11 deletions(-) create mode 100644 src/CorruptedPathDetected.php diff --git a/.gitignore b/.gitignore index bd11bfd9d..bfcf19834 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .php_cs.cache +.phpunit.result.cache php-cs-fixer bin composer.lock diff --git a/src/CorruptedPathDetected.php b/src/CorruptedPathDetected.php new file mode 100644 index 000000000..81a27e5f2 --- /dev/null +++ b/src/CorruptedPathDetected.php @@ -0,0 +1,17 @@ +assertEquals(3, Util::contentSize('135')); } + /** + * @dataProvider dbCorruptedPath + */ + public function testRejectingPathWithFunkyWhitespace($path) + { + $this->expectException(CorruptedPathDetected::class); + Util::normalizePath($path); + } + + /** + * @return array + */ + public function dbCorruptedPath() + { + return [["some\0/path.txt"], ["s\x09i.php"]]; + } + public function mapProvider() { return [ @@ -95,7 +112,7 @@ public function invalidPathProvider() } /** - * @dataProvider invalidPathProvider + * @dataProvider invalidPathProvider */ public function testOutsideRootPath($path) { @@ -125,7 +142,6 @@ public function pathProvider() ['example/path/..txt', 'example/path/..txt'], ['\\example\\path.txt', 'example/path.txt'], ['\\example\\..\\path.txt', 'path.txt'], - ["some\0/path.txt", 'some/path.txt'], ]; }