|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63876 multiget returns an array with keys containing chars <= 0x20 being broken
Submitted: 2012-12-30 19:34 UTC Modified: 2013-02-18 00:36 UTC
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: alex dot offshore at gmail dot com Assigned:
Status: No Feedback Package: memcache (PECL)
PHP Version: Irrelevant OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: alex dot offshore at gmail dot com
New email:
PHP Version: OS:


 [2012-12-30 19:34 UTC] alex dot offshore at gmail dot com
When using Memcache::get for retrieving multiple entries, the keys of returned array may be broken, if key names contain some chars from 0x00 to 0x20. Everything is OK when using Memcache::get to retrieve single value.

Tested with PHP 5.4.9 and PHP 5.3.10 (version is irrelevant); php-memcache versions 3.0.6, 3.0.7 and 2.2.7; memcached 1.4.13.

Test script:

$memcache = new Memcache();
$memcache->connect('localhost', '11211');

$prefix = 'TEST_';
$hex_key = '310e323334';
$key = $prefix . hex2bin($hex_key);

$value = 'test';

echo "Trying key: $prefix($hex_key)\n";

$set_result = $memcache->set($key, $value) !== false;
echo "set: " . ($set_result ? 'ok' : 'fail') . "\n";

$get_result_expected = $value;
$get_result = $memcache->get($key);
echo "get: " . (($get_result === $get_result_expected) ? 'ok' : 'fail') . ", '" . serialize($get_result) . "' vs '" . serialize($get_result_expected) . "'\n";

$multiget_result_expected = array($key => $value);
$multiget_result = $memcache->get(array($key));
echo "multiget: " . (($multiget_result === $multiget_result_expected) ? 'ok' : 'fail') . ", '" . serialize($multiget_result) . "' vs '" . serialize($multiget_result_expected) . "'\n";

echo "\n\n";

Expected result:
Trying key: TEST_(310e323334)
set: ok
get: ok, 's:4:"test";' vs 's:4:"test";'
multiget: fail, 'a:1:{s:10:"TEST_1_234";s:4:"test";}' vs 'a:1:{s:10:"TEST_1234";s:4:"test";}'

Actual result:
Trying key: TEST_(310e323334)
set: ok
get: ok, 's:4:"test";' vs 's:4:"test";'
multiget: ok, 'a:1:{s:10:"TEST_1?234";s:4:"test";}' vs 'a:1:{s:10:"TEST_1?234";s:4:"test";}'

(note: the "?" mark represents non-printable char)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-12-30 20:46 UTC] alex dot offshore at gmail dot com
Sorry, exchg Expected/Actual texts.
 [2012-12-31 10:42 UTC]
memcache used to support only plain-text protocol some time ago, which didn't 
support binary keys or keys containing whitespaces for apparent reasons.
Because of that PECL/memcache sanitizes all the keys to make sure the resulting 
request string is valid and cannot be broken by malicious user input.
I'm not quite sure what's the status of such keys in the binary protocol, but I 
suspect it'd make very little sense to change PECL/memcache to support them.
What's the point in using binary keys in the first place?

Here's what memcached protocol documentation says:
Data stored by memcached is identified with the help of a key. A key
is a text string which should uniquely identify the data for clients
that are interested in storing and retrieving it.  Currently the
length limit of a key is set at 250 characters (of course, normally
clients wouldn't need to use such long keys); the key must not include
control characters or whitespace.
 [2012-12-31 10:42 UTC]
-Status: Open +Status: Feedback
 [2013-02-18 00:36 UTC] pecl-dev at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 29 11:01:32 2024 UTC