PHP 4.0 Bug #6340 Updated: ord() function causes php to crash
| From: | Bug Database | Date: | Thu, 24 Aug 2000 23:36:44 +0000 |
| Subject: | PHP 4.0 Bug #6340 Updated: ord() function causes php to crash | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-30577@lists.php.net to get a copy of this message | ||
ID: 6340
User Update by: aaron@meta.lo-res.org
Status: Open
Bug Type: Reproduceable crash
Description: ord() function causes php to crash
Sorry, again a correction:
the problem was NOT the ord() function, but rather that PHP will not cope with large integers (even
below 2^31).
Maybe the problem was the modulo operator and large numbers.
I will reprint my original source here:
function hash($str) {
// $p = 4294967291; /* largest prime <= 2^32 */
// $p = 2147483647; /* largest prime <= 2^31 */
// $p = 1073741789; /* largest prime <= 2^30 */
// $p = 268435399; /* largest prime <= 2^28 */
$p = 33554393 ; /* largest prime <= 2^25 */
// $p = 65521; /* largest prime <= sqrt(2^32) */
$BASE = 256; /* largest char */
if ($str == -1) {
return -1;
}
$len = strlen($str);
$hash = ord($str[0]);
for ($i = 1; $i < $len; $i++) {
debug("i = $i");
$hash = (($hash * 32) + ord($str[$i])) % $p;
debug("hash = $hash");
}
return $hash;
}
----
you can see from the values for $p some kind of boundary where the arithmetic ops wont work anymore.
The debug() function basically echos the given string parameter. so nothing special about that.
Unfortunately I cannot change the name of the PR anymore but still please keep me informed what I
can do to work with large numbers.
thanks,
aaron.
Full Bug description available at: http://bugs.php.net/?id=6340