Forum: NGINX memcache buffer overflow?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2974d09ac2541e892966b762aad84943?d=identicon&s=25 batrick (Guest)
on 2009-05-18 21:20
(Received via mailing list)
Dear all,

I am trying to get memcache with nginx to work to improve the
performance of my php web application. However, while my configuration
is working fine for small outputs, if output size exceeds 20k I only get
garbage characters posted back to the client. The test was carried out
on debian lenny, with nginx version nginx/0.6.32

Test Code:

--- snip
<?php
$length = 20;

$memcache = new Memcache;
$memcache->connect('localhost', '11211');
$x='';
for($i=0;$i<$length*1024;$i++) {
    $x .= 'x';
}
$memcache->set('/k',$x, 0,  6100);
echo strlen($memcache->get('/k'));
--- snap

If I run this code with length set to 20, the string is correctly stored
in memcache (as verified by reading from the memcache). However, nginx
returns garbage characters only - especially NULL strings.

If length is reduced to 19, both the memcache module and the script
correctly output the x's.

I would be very grateful if this bug could be fixed. Please do not
hesistate to contact me if you need more information.

Kind regards,

batrick

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,2160,2160#msg-2160
96321bb7fd6f712aa7785ce2d58388f2?d=identicon&s=25 Anton Yuzhaninov (Guest)
on 2009-05-18 23:39
(Received via mailing list)
batrick wrote:
> $x='';
> for($i=0;$i<$length*1024;$i++) {
>     $x .= 'x';
> }
> $memcache->set('/k',$x, 0,  6100);
> echo strlen($memcache->get('/k'));
> --- snap
>
> If I run this code with length set to 20, the string is correctly stored in memcache (as 
verified by reading from the memcache). However, nginx returns garbage characters only - 
especially NULL strings.
>
> If length is reduced to 19, both the memcache module and the script correctly output the 
x's.

don't forget to disable gzip compression of values stored in memcached
by php:
http://php.net/manual/en/function.memcache-setcomp...
2974d09ac2541e892966b762aad84943?d=identicon&s=25 batrick (Guest)
on 2009-05-19 17:17
(Received via mailing list)
Hi Anton,

many thanks for this. The problem is indeed that the PHP memcache client
by default enables compression for large objects. When retrieving the
memcache object from PHP everything appears fine, but nginx does not
handle the compression. The feature can be disabled by setting the
"minimum required saving" before compression to 100%:

$memcache->setCompressThreshold(0, 1);

I hope this will be helpful to anyone else with this problem and once
again thanks to Anton for his prompt help!

Kind regards,

Batrick

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,2160,2164#msg-2164
This topic is locked and can not be replied to.