note 100060 modified in function.crc32 by danbrown
| From: | danbrown@php.net | Date: | Thu, 06 Oct 2011 21:24:58 +0000 |
| Subject: | note 100060 modified in function.crc32 by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-183679@lists.php.net to get a copy of this message | ||
The crc32_combine() function provided by petteri at qred dot fi has a bug that causes an infinite
loop, a shift operation on a 32-bit signed int might never reach zero. Replacing the function
gf2_matrix_times() with the following seems to fix it:
<?php
function gf2_matrix_times($mat, $vec)
{
$sum=0;
$i=0;
while ($vec) {
if ($vec & 1) {
$sum ^= $mat[$i];
}
$vec = ($vec >> 1) & 0x7FFFFFFF;
$i++;
}
return $sum;
}
?>
Otherwise, it's probably the best solution if you can't use hash_file(). Using a 1meg read
buffer, the function only takes twice as long to process a 300meg files than hash_file() in my test.
--was--
The crc32_combine() function provided by petteri at qred dot fi has a bug that causes an infinite
loop, a shift operation on a 32-bit signed int might never reach zero. Replacing the function
gf2_matrix_times() with the following seems to fix it:
function gf2_matrix_times($mat, $vec)
{
$sum=0;
$i=0;
while ($vec) {
if ($vec & 1) {
$sum ^= $mat[$i];
}
$vec = ($vec >> 1) & 0x7FFFFFFF;
$i++;
}
return $sum;
}
Otherwise, it's probably the best solution if you can't use hash_file(). Using a 1meg read
buffer, the function only takes twice as long to process a 300meg files than hash_file() in my test.
http://php.net/manual/en/function.crc32.php