Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

fix for issue 6076. avoid GlobIterator globbing to directories which it ... #6077

Merged
merged 4 commits into from

4 participants

@brettmc

...will subsequently fail to unlink() by appending . instead of just * to path in clearByNamespace() and clearByPrefix(). . will glob to both .dat and .tag extensions

@brettmc brettmc fix for issue 6076. avoid GlobIterator globbing to directories which …
…it will subsequently fail to unlink() by appending *.* instead of just * to path in clearByNamespace() and clearByPrefix(). *.* will glob to both .dat and .tag extensions
44f752c
@Ocramius
Collaborator

@brettmc can you provide a test for this one?

@Ocramius Ocramius added Cache and removed Stdlib labels
@Ocramius
Collaborator

See #6076

@brettmc brettmc add unit test for clearByNamespace. Attempting to write a unit test f…
…or clearByPrefix shows that it's actually not an issue (due to the prefix itself differentiating a file from a dir), so revert my change to clearByPrefix
c991bb2
@marc-mabe

As noted in #6076 it should be done for clearByPrefix(), too

brettmc added some commits
@brettmc brettmc add fix and unit test for the case where Filesystem::clearByPrefix() …
…can try to remove a directory (eg if the prefix happens to collide with a partial md5 key), as pointed out by @marc-mabe in issue 6076
cf38174
@brettmc brettmc php_cs whitespace cleanup 9651573
@weierophinney weierophinney added this to the 2.3.1 milestone
@weierophinney weierophinney self-assigned this
@weierophinney weierophinney merged commit 9651573 into zendframework:master

1 check passed

Details continuous-integration/travis-ci The Travis CI build passed
@weierophinney weierophinney referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/6077'
Close #6077
Fixes #6076
bb37d91
@brettmc brettmc deleted the unknown repository branch
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-cache
@weierophinney weierophinney Merge pull request zendframework/zf2#6077 from brettmc/zf6076
fix for issue 6076. avoid GlobIterator globbing to directories which it ...

Conflicts:
	tests/ZendTest/Cache/Storage/Adapter/FilesystemTest.php
880e948
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-cache
@weierophinney weierophinney Merge branch 'hotfix/6077' 1cd130f
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-cache
@weierophinney weierophinney Merge branch 'hotfix/6077' into develop ba2ccbf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 2, 2014
  1. @brettmc

    fix for issue 6076. avoid GlobIterator globbing to directories which …

    brettmc authored
    …it will subsequently fail to unlink() by appending *.* instead of just * to path in clearByNamespace() and clearByPrefix(). *.* will glob to both .dat and .tag extensions
  2. @brettmc

    add unit test for clearByNamespace. Attempting to write a unit test f…

    brettmc authored
    …or clearByPrefix shows that it's actually not an issue (due to the prefix itself differentiating a file from a dir), so revert my change to clearByPrefix
Commits on Apr 7, 2014
  1. @brettmc

    add fix and unit test for the case where Filesystem::clearByPrefix() …

    brettmc authored
    …can try to remove a directory (eg if the prefix happens to collide with a partial md5 key), as pointed out by @marc-mabe in issue 6076
  2. @brettmc

    php_cs whitespace cleanup

    brettmc authored
This page is out of date. Refresh to see the latest.
View
4 library/Zend/Cache/Storage/Adapter/Filesystem.php
@@ -189,7 +189,7 @@ public function clearByNamespace($namespace)
$flags = GlobIterator::SKIP_DOTS | GlobIterator::CURRENT_AS_PATHNAME;
$path = $options->getCacheDir()
. str_repeat(DIRECTORY_SEPARATOR . $prefix . '*', $options->getDirLevel())
- . DIRECTORY_SEPARATOR . $prefix . '*';
+ . DIRECTORY_SEPARATOR . $prefix . '*.*';
$glob = new GlobIterator($path, $flags);
ErrorHandler::start();
@@ -227,7 +227,7 @@ public function clearByPrefix($prefix)
$flags = GlobIterator::SKIP_DOTS | GlobIterator::CURRENT_AS_PATHNAME;
$path = $options->getCacheDir()
. str_repeat(DIRECTORY_SEPARATOR . $nsPrefix . '*', $options->getDirLevel())
- . DIRECTORY_SEPARATOR . $nsPrefix . $prefix . '*';
+ . DIRECTORY_SEPARATOR . $nsPrefix . $prefix . '*.*';
$glob = new GlobIterator($path, $flags);
ErrorHandler::start();
View
23 tests/ZendTest/Cache/Storage/Adapter/FilesystemTest.php
@@ -281,4 +281,27 @@ public function testGetMetadataWithAtime()
$expectedAtime = fileatime($meta['filespec'] . '.dat');
$this->assertEquals($expectedAtime, $meta['atime']);
}
+
+ public function testClearByNamespaceWithUnexpectedDirectory()
+ {
+ // create cache items at 2 different directory levels
+ $this->_storage->getOptions()->setDirLevel(2);
+ $this->_storage->setItem('a_key', 'a_value');
+ $this->_storage->getOptions()->setDirLevel(1);
+ $this->_storage->setItem('b_key', 'b_value');
+ $this->_storage->clearByNamespace($this->_storage->getOptions()->getNamespace());
+ }
+
+ public function testClearByPrefixWithUnexpectedDirectory()
+ {
+ // create cache items at 2 different directory levels
+ $this->_storage->getOptions()->setDirLevel(2);
+ $this->_storage->setItem('a_key', 'a_value');
+ $this->_storage->getOptions()->setDirLevel(1);
+ $this->_storage->setItem('b_key', 'b_value');
+ $glob = glob($this->_tmpCacheDir.'/*');
+ //contrived prefix which will collide with an existing directory
+ $prefix = substr(md5('a_key'), 2, 2);
+ $this->_storage->clearByPrefix($prefix);
+ }
}
Something went wrong with that request. Please try again.