Merge branch '3.4' into 4.3

* 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
This commit is contained in:
Nicolas Grekas 2019-11-12 14:07:20 +01:00
commit 2baf53aa7a
6 changed files with 34 additions and 3 deletions

View File

@ -286,6 +286,16 @@ class TagAwareAdapter implements TagAwareAdapterInterface, TagAwareCacheInterfac
return $this->invalidateTags([]); return $this->invalidateTags([]);
} }
public function __sleep()
{
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
}
public function __wakeup()
{
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
}
public function __destruct() public function __destruct()
{ {
$this->commit(); $this->commit();

View File

@ -108,6 +108,16 @@ trait AbstractAdapterTrait
return true; return true;
} }
public function __sleep()
{
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
}
public function __wakeup()
{
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
}
public function __destruct() public function __destruct()
{ {
if ($this->deferred) { if ($this->deferred) {

View File

@ -36,7 +36,7 @@ class FileBinaryMimeTypeGuesser implements MimeTypeGuesserInterface
* *
* @param string $cmd The command to run to get the mime type of a file * @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; $this->cmd = $cmd;
} }
@ -85,7 +85,7 @@ class FileBinaryMimeTypeGuesser implements MimeTypeGuesserInterface
ob_start(); ob_start();
// need to use --mime instead of -i. see #6641 // 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) { if ($return > 0) {
ob_end_clean(); ob_end_clean();

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 B

View File

@ -21,6 +21,17 @@ use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;
*/ */
class MimeTypeTest extends TestCase 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() public function testGuessImageWithoutExtension()
{ {
$this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test')); $this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test'));

View File

@ -79,7 +79,7 @@ class UriSigner
$hash = $params[$this->parameter]; $hash = $params[$this->parameter];
unset($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) private function computeHash($uri)