#30598 [NEW]: double to long truncation breaks TEA
From: os at sumu dot org
Operating system: Any
PHP version: 5.0.2
PHP Bug Type: Zend Engine 2 problem
Bug description: double to long truncation breaks TEA
Description:
------------
The change for DVAL_TO_LVAL macro in 5.0.2 breaks some of my code that
worked in earlier versions. While it appears that it was relying on
undefined behaviour, it allowed for example a direct port of Tiny
Encryption Algorithm's reference C code for PHP to work.
(http://en.wikipedia.org/wiki/Tiny_Encryption_Algorithm)
Reproduce code:
---------------
function tea_encrypt($cycle, $key)
{
$a = $cycle[0];
$b = $cycle[1];
$sum = 0;
$delta = (int)0x9e3779b9;
for($i=0; $i<32; $i++)
{
$sum = (int)($sum + $delta);
$a += (($b << 4) + $key[1]) ^ ($b + $sum) ^ (($b >> 5) +
$key[2]);
$b += (($a << 4) + $key[3]) ^ ($a + $sum) ^ (($a >> 5) +
$key[4]);
}
return array($a, $b);
}
$result = tea_encrypt(array(123456, 987654), array(0, 1, 2, 3, 4));
var_dump(unpack("H*", pack("V*", $result[0], $result[1])));
Expected result:
----------------
PHP versions prior to 5.0.2:
~> php -q tea.php
array(1) {
[1]=>
string(16) "8f695fc4e6d3c507"
}
Actual result:
--------------
~> ./php-5.0.2/sapi/cli/php -q tea.php
array(1) {
[1]=>
string(16) "ffffff7f00000080"
}
--
Edit bug report at http://bugs.php.net/?id=30598&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=30598&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=30598&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=30598&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=30598&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=30598&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=30598&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=30598&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=30598&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=30598&r=support
Expected behavior: http://bugs.php.net/fix.php?id=30598&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=30598&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=30598&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=30598&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=30598&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=30598&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=30598&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=30598&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=30598&r=float
MySQL Configuration Error: http://bugs.php.net/fix.php?id=30598&r=mysqlcfg
Thread (3 messages)
- os at sumu dot org