php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #59356 cas_token overflowed and missed cas command
Submitted: 2010-08-10 06:53 UTC Modified: 2021-06-09 11:25 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: isao dot kata at gmail dot com Assigned: cmb (profile)
Status: Closed Package: memcached (PECL)
PHP Version: 5.2.13 OS: Linux / CentOS 5.4
Private report: No CVE-ID: None
 [2010-08-10 06:53 UTC] isao dot kata at gmail dot com
Description:
------------
Hi

I was encountered that "cas_token" overflowed and missed cas 
command when I used "kumofs", a distributed key-value store 
which supports memcached text protocol.

http://github.com/etolabo/kumofs

It seems that kumofs returns cas_token within uint64_t 
range, protocols are as follows.

===
telnet localhost 11311
version
VERSION kumofs-0.4.11
gets cas_count
VALUE cas_count 1 2 5503666394124107763
30
===

Pecl::Memcached seems to cast type of "cas_token" from 
uint64_t to double, but in PHP, cas_token isn't precisely 
equal value expected. I wonder it is because of overflow 
occured in casting uint64_t to double.

I finally found an ad-hoc solution (attached in Reproduce 
code area), but I wish this package will solve this overflow 
problem.

This is my first report to maintainer and I feel very 
nervous. If I have any problem, please let me know.

Best regards,

Isao Katayama

Reproduce code:
---------------
--- php_memcached.c    (revision 3366)
+++ php_memcached.c    (revision 3367)
@@ -428,7 +428,7 @@
 }

 zval_dtor(cas_token);
-        ZVAL_DOUBLE(cas_token, (double)cas);
+        ZVAL_DOUBLE(cas_token, *((double *)(&cas)));

 memcached_result_free(&result);

@@ -1231,7 +1231,7 @@
 RETURN_FALSE;
 }

-    DVAL_TO_LVAL(cas_d, cas);
+    cas = *((uint64_t *)(&cas_d));

 if (i_obj->compression) {
 flags |= MEMC_VAL_COMPRESSED;


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-05 07:22 UTC] nick dot madigan at baltsun dot com
This has made my day. I wish all ptsoigns were this good.
 [2012-10-27 20:39 UTC] jeremy dot belloir at gmail dot com
Thank you! You save my project.
I use Mysql Cluster & Memcached support (with ndb api) and I had the same problem.
This bug is identified (and suggested patch!) since 2 years my god...

Your patch works fine with PHP5.4.5 (latest version), PECL::Memcached-2.1.0
(latest version) [on Debian 6]
 [2021-06-09 11:25 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-06-09 11:25 UTC] cmb@php.net
The memcached bug tracker is now on Github[1].  If this is still
an issue with the current memcached version, please report there.

[1] <https://github.com/php-memcached-dev/php-memcached/issues>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 05 10:01:32 2024 UTC