Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f4a02b4

Browse filesBrowse files
bug #39420 [Cache] Prevent notice on case matching metadata trick (bastnic)
This PR was submitted for the 5.1 branch but it was merged into the 4.4 branch instead. Discussion ---------- [Cache] Prevent notice on case matching metadata trick | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | | License | MIT On saving an array of one element with a int key of strlen 10 it matches the first conditions of the trick used to save metadata. > Notice: Trying to access array offset on value of type int Casting it to string fixes it. Commits ------- a91ac74 [Cache] Prevent notice on case matching metadata trick
2 parents 2dd4561 + a91ac74 commit f4a02b4
Copy full SHA for f4a02b4

File tree

Expand file treeCollapse file tree

3 files changed

+26
-2
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+26
-2
lines changed

‎src/Symfony/Component/Cache/Adapter/AbstractAdapter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/AbstractAdapter.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static function ($key, $value, $isHit) {
5151
// Detect wrapped values that encode for their expiry and creation duration
5252
// For compactness, these values are packed in the key of an array using
5353
// magic numbers in the form 9D-..-..-..-..-00-..-..-..-5F
54-
if (\is_array($v) && 1 === \count($v) && 10 === \strlen($k = key($v)) && "\x9D" === $k[0] && "\0" === $k[5] && "\x5F" === $k[9]) {
54+
if (\is_array($v) && 1 === \count($v) && 10 === \strlen($k = (string) key($v)) && "\x9D" === $k[0] && "\0" === $k[5] && "\x5F" === $k[9]) {
5555
$item->value = $v[$k];
5656
$v = unpack('Ve/Nc', substr($k, 1, -1));
5757
$item->metadata[CacheItem::METADATA_EXPIRY] = $v['e'] + CacheItem::METADATA_EXPIRY_OFFSET;

‎src/Symfony/Component/Cache/Adapter/ProxyAdapter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/ProxyAdapter.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static function ($key, $innerItem) use ($poolHash) {
5959
// Detect wrapped values that encode for their expiry and creation duration
6060
// For compactness, these values are packed in the key of an array using
6161
// magic numbers in the form 9D-..-..-..-..-00-..-..-..-5F
62-
if (\is_array($v) && 1 === \count($v) && 10 === \strlen($k = key($v)) && "\x9D" === $k[0] && "\0" === $k[5] && "\x5F" === $k[9]) {
62+
if (\is_array($v) && 1 === \count($v) && 10 === \strlen($k = (string) key($v)) && "\x9D" === $k[0] && "\0" === $k[5] && "\x5F" === $k[9]) {
6363
$item->value = $v[$k];
6464
$v = unpack('Ve/Nc', substr($k, 1, -1));
6565
$item->metadata[CacheItem::METADATA_EXPIRY] = $v['e'] + CacheItem::METADATA_EXPIRY_OFFSET;

‎src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,30 @@ public function testClearPrefix()
272272
$this->assertFalse($cache->hasItem('foobar'));
273273
$this->assertTrue($cache->hasItem('barfoo'));
274274
}
275+
276+
public function testWeirdDataMatchingMetadataWrappedValues()
277+
{
278+
if (isset($this->skippedTests[__FUNCTION__])) {
279+
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
280+
}
281+
282+
$cache = $this->createCachePool(0, __FUNCTION__);
283+
$cache->clear();
284+
285+
$item = $cache->getItem('foobar');
286+
287+
// it should be an array containing only one element
288+
// with key having a strlen of 10.
289+
$weirdDataMatchingMedatataWrappedValue = [
290+
1234567890 => [
291+
1,
292+
],
293+
];
294+
295+
$cache->save($item->set($weirdDataMatchingMedatataWrappedValue));
296+
297+
$this->assertTrue($cache->hasItem('foobar'));
298+
}
275299
}
276300

277301
class NotUnserializable

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.