Last modified: 2008-09-27 23:40:39 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T14342, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 12342 - get_sock() in memcached-client.php calculates hash in wrong way
get_sock() in memcached-client.php calculates hash in wrong way
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
General/Unknown (Other open bugs)
1.12.x
All All
: Normal normal (vote)
: ---
Assigned To: Nobody - You can work on this!
: patch-need-review
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2007-12-18 17:58 UTC by Marooned
Modified: 2008-09-27 23:40 UTC (History)
1 user (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Marooned 2007-12-18 17:58:46 UTC
Function get_sock uses loop for for searching for memcache server.
This is:

<pre>      for ($tries = 0; $tries<20; $tries++)
      {
         $host = $this->_buckets[$hv % $this->_bucketcount];
         $sock = $this->sock_to_host($host);
         if (is_resource($sock)) {
            $this->_flush_read_buffer($sock);
            return $sock;
         }
         $hv += $this->_hashfunc($tries . $realkey);
      }</pre>

If there are servers in _buckets then the if(is_resource..) is true and loop exits.

However, if there is no good server then the line:
<pre>$hv += $this->_hashfunc($tries . $realkey);</pre>
is reached and the $hv is increased. In the next loop passes <pre>$hv % $this->_bucketcount</pre> will return negative numbers as the $hv will pass beyond the bounds of the integer type.

My idea to fix it is to change
<pre>$hv += $this->_hashfunc($tries . $realkey);</pre>
to:
<pre>$hv ^= $this->_hashfunc($tries . $realkey);</pre>
or:
<pre>$hv += $this->_hashfunc($tries . $realkey);
$hv ^= 0x7fffffff;</pre>

One should performe a test of distribution of this variable (a histogram) after making this changes.
Comment 1 Marooned 2007-12-18 18:02:58 UTC
Ech.. there is no "preview" or "edit" option [why?] nor the help about tags that can be used to format this text.

If someone who can edit will see it - please - remove/change the <pre> above to something that is accepted here to format a code *and* delete this comment.

Thanks
Comment 2 Marooned 2007-12-19 16:40:54 UTC
Ah! What a terrible mistake!
The last suggested version should be:

$hv += $this->_hashfunc($tries . $realkey);
$hv &= 0x7fffffff;

That is '&' instead of '^' of course! I'm sorry for that typo.
[and this is a version which I use on my local test MW]
Comment 3 Aaron Schulz 2008-09-27 23:21:33 UTC
This would explain the mysterious negative indexes that popped up on a maintenance script
Comment 4 Aaron Schulz 2008-09-27 23:36:41 UTC
Fixed in r41326
Comment 5 Marooned 2008-09-27 23:40:39 UTC
Thanks for applying this fix.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links