8000 [Cache] Hash using B64+MD5 in FilesystemAdapter · symfony/symfony@e96bb10 · GitHub
[go: up one dir, main page]

Skip to content

Commit e96bb10

Browse files
[Cache] Hash using B64+MD5 in FilesystemAdapter
1 parent 6fb9fee commit e96bb10

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/Symfony/Component/Cache/Adapter/FilesystemAdapter.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct($directory, $defaultLifetime = null)
3434
throw new InvalidArgumentException(sprintf('Cache directory is not writable (%s)', $directory));
3535
}
3636
// On Windows the whole path is limited to 258 chars
37-
if ('\\' === DIRECTORY_SEPARATOR && strlen($dir) > 190) {
37+
if ('\\' === DIRECTORY_SEPARATOR && strlen($dir) > 234) {
3838
throw new InvalidArgumentException(sprintf('Cache directory too long (%s)', $directory));
3939
}
4040

@@ -62,10 +62,13 @@ protected function doFetch(array $ids)
6262
@unlink($file);
6363
}
6464
} else {
65+
$i = rawurldecode(rtrim(fgets($h)));
6566
$value = stream_get_contents($h);
6667
flock($h, LOCK_UN);
6768
fclose($h);
68-
$values[$id] = unserialize($value);
69+
if ($i === $id) {
70+
$values[$id] = unserialize($value);
71+
}
6972
}
7073
}
7174

@@ -125,7 +128,7 @@ protected function doSave(array $values, $lifetime)
125128
if (!file_exists($dir)) {
126129
@mkdir($dir, 0777, true);
127130
}
128-
$value = $expiresAt."\n".serialize($value);
131+
$value = $expiresAt."\n".rawurlencode($id)."\n".serialize($value);
129132
if (false !== @file_put_contents($file, $value, LOCK_EX)) {
130133
@touch($file, $expiresAt);
131134
} else {
@@ -138,8 +141,8 @@ protected function doSave(array $values, $lifetime)
138141

139142
private function getFile($id)
140143
{
141-
$hash = hash('sha256', $id);
144+
$hash = str_replace('/', '-', base64_encode(md5($id, true)));
142145

143-
return $this->directory.$hash[0].DIRECTORY_SEPARATOR.$hash[1].DIRECTORY_SEPARATOR.$hash;
146+
return $this->directory.$hash[0].DIRECTORY_SEPARATOR.$hash[1].DIRECTORY_SEPARATOR.substr($hash, 2, -2);
144147
}
145148
}

0 commit comments

Comments
 (0)
0