Skip to content

Commit

Permalink
Merge branch '3.4' into 4.3
Browse files Browse the repository at this point in the history
* 3.4:
  [HttpFoundation] fix guessing mime-types of files with leading dash
  [Cache] forbid serializing AbstractAdapter and TagAwareAdapter instances
  Use constant time comparison in UriSigner
  • Loading branch information
nicolas-grekas committed Nov 12, 2019
2 parents 4bc7e9c + 4cc37df commit 2baf53a
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php
Expand Up @@ -286,6 +286,16 @@ public function commit()
return $this->invalidateTags([]);
}

public function __sleep()
{
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
}

public function __wakeup()
{
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
}

public function __destruct()
{
$this->commit();
Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/Cache/Traits/AbstractAdapterTrait.php
Expand Up @@ -108,6 +108,16 @@ public function saveDeferred(CacheItemInterface $item)
return true;
}

public function __sleep()
{
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
}

public function __wakeup()
{
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
}

public function __destruct()
{
if ($this->deferred) {
Expand Down
Expand Up @@ -36,7 +36,7 @@ class FileBinaryMimeTypeGuesser implements MimeTypeGuesserInterface
*
* @param string $cmd The command to run to get the mime type of a file
*/
public function __construct(string $cmd = 'file -b --mime %s 2>/dev/null')
public function __construct(string $cmd = 'file -b --mime -- %s 2>/dev/null')
{
$this->cmd = $cmd;
}
Expand Down Expand Up @@ -85,7 +85,7 @@ public function guess($path)
ob_start();

// need to use --mime instead of -i. see #6641
passthru(sprintf($this->cmd, escapeshellarg($path)), $return);
passthru(sprintf($this->cmd, escapeshellarg((0 === strpos($path, '-') ? './' : '').$path)), $return);
if ($return > 0) {
ob_end_clean();

Expand Down
Binary file not shown.
Expand Up @@ -21,6 +21,17 @@
*/
class MimeTypeTest extends TestCase
{
public function testGuessWithLeadingDash()
{
$cwd = getcwd();
chdir(__DIR__.'/../Fixtures');
try {
$this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess('-test'));
} finally {
chdir($cwd);
}
}

public function testGuessImageWithoutExtension()
{
$this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test'));
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpKernel/UriSigner.php
Expand Up @@ -79,7 +79,7 @@ public function check($uri)
$hash = $params[$this->parameter];
unset($params[$this->parameter]);

return $this->computeHash($this->buildUrl($url, $params)) === $hash;
return hash_equals($this->computeHash($this->buildUrl($url, $params)), $hash);
}

private function computeHash($uri)
Expand Down

0 comments on commit 2baf53a

Please sign in to comment.