php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30598 double to long truncation breaks TEA
Submitted: 2004-10-28 15:15 UTC Modified: 2004-10-28 15:26 UTC
From: os at sumu dot org Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.0.2 OS: Any
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: os at sumu dot org
New email:
PHP Version: OS:

 

 [2004-10-28 15:15 UTC] os at sumu dot org
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"
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-10-28 15:23 UTC] os at sumu dot org
Oops.. looks like I should've searched the bug database a bit more, this is basically a duplicate to #30315.
 [2004-10-28 15:26 UTC] derick@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

Duplicate of #30315.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Mon Aug 03 15:00:01 2026 UTC