From 6d4a658ab7a6860f1106565aa1d97f004d37dd56 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 9 Nov 2016 12:04:28 +0100 Subject: [PATCH] [Cache] Make directory hashing case insensitive --- .../DependencyInjection/Compiler/CachePoolPass.php | 2 +- .../DependencyInjection/FrameworkExtension.php | 2 +- .../DependencyInjection/Compiler/CachePoolPassTest.php | 4 ++-- src/Symfony/Component/Cache/Adapter/FilesystemAdapter.php | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php index 49e97b73c6402..1748862219ddf 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php @@ -84,7 +84,7 @@ public function process(ContainerBuilder $container) private function getNamespace($namespaceSuffix, $id) { - return substr(str_replace('/', '-', base64_encode(md5($id.$namespaceSuffix, true))), 0, 10); + return substr(str_replace('/', '-', base64_encode(hash('sha256', $id.$namespaceSuffix, true))), 0, 10); } /** diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 3a2e40dcf60c3..9e9d797191a4e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -1037,7 +1037,7 @@ private function registerPropertyInfoConfiguration(array $config, ContainerBuild private function registerCacheConfiguration(array $config, ContainerBuilder $container) { - $version = substr(str_replace('/', '-', base64_encode(md5(uniqid(mt_rand(), true), true))), 0, -2); + $version = substr(str_replace('/', '-', base64_encode(hash('sha256', uniqid(mt_rand(), true), true))), 0, 22); $container->getDefinition('cache.adapter.apcu')->replaceArgument(2, $version); $container->getDefinition('cache.adapter.system')->replaceArgument(2, $version); $container->getDefinition('cache.adapter.filesystem')->replaceArgument(2, $config['directory']); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolPassTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolPassTest.php index 1f77cdd0fe60b..53cb95837f7e8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolPassTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolPassTest.php @@ -41,7 +41,7 @@ public function testNamespaceArgumentIsReplaced() $this->cachePoolPass->process($container); - $this->assertSame('VcRIZlUhEv', $cachePool->getArgument(0)); + $this->assertSame('kRFqMp5odS', $cachePool->getArgument(0)); } public function testArgsAreReplaced() @@ -61,7 +61,7 @@ public function testArgsAreReplaced() $this->assertInstanceOf(Reference::class, $cachePool->getArgument(0)); $this->assertSame('foobar', (string) $cachePool->getArgument(0)); - $this->assertSame('VcRIZlUhEv', $cachePool->getArgument(1)); + $this->assertSame('kRFqMp5odS', $cachePool->getArgument(1)); $this->assertSame(3, $cachePool->getArgument(2)); } diff --git a/src/Symfony/Component/Cache/Adapter/FilesystemAdapter.php b/src/Symfony/Component/Cache/Adapter/FilesystemAdapter.php index 4734f71ee2a1f..81886b4d11a54 100644 --- a/src/Symfony/Component/Cache/Adapter/FilesystemAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/FilesystemAdapter.php @@ -146,13 +146,13 @@ protected function doSave(array $values, $lifetime) private function getFile($id, $mkdir = false) { - $hash = str_replace('/', '-', base64_encode(md5($id, true))); - $dir = $this->directory.$hash[0].DIRECTORY_SEPARATOR.$hash[1].DIRECTORY_SEPARATOR; + $hash = str_replace('/', '-', base64_encode(hash('sha256', $id, true))); + $dir = $this->directory.strtoupper($hash[0].DIRECTORY_SEPARATOR.$hash[1].DIRECTORY_SEPARATOR); if ($mkdir && !file_exists($dir)) { @mkdir($dir, 0777, true); } - return $dir.substr($hash, 2, -2); + return $dir.substr($hash, 2, 20); } }