[PHP] unpack bug?

2009-01-15 Thread James Lucas

Hi,

I have some code developed on a linux system with PHP 5.1.6, its using 
the PEAR Net_DNS class to send dns updates, part of this requires 
unpacking a binary string, an example is below.


This works on PHP 5.1.6 but fails on 5.2.8, it appears that it may be in 
relation to the following change in 5.2.4 "Added missing format 
validator to unpack()".


A test case of the code is as follows:

$data = 
base64_decode("A86pgAABCHJuZGMta2V5AAD6AP8AADoIaG1hYy1tZDUHc2lnLWFsZwNyZWcDaW50SW8kgAEsABBd7hm4xnUjl5kWLXfbZKaBA84A");

$offset=58;
$d = unpack('\...@$offset/nth/Ntl/nfudge/nmac_size', $data);
print_r($d);

Expected output:
Array
(
   [th] => 974
   [tl] => -1451229184
   [fudge] => 0
   [mac_size] => 0
)
Actual output:
Warning: unpack(): Invalid format type \

Removing the "\" before that @ does make the error go away but causes a 
different result:


Array
(
   [th] => 52905
   [tl] => -2147483648
   [fudge] => 0
   [mac_size] => 0
)

Is this being caused by the format validator and if so should it be 
allowing this, or is there another way I can unpack this correctly.


Regards

James



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: unpack bug?

2009-01-15 Thread James Lucas

Nathan Rixham wrote:
it's the pack offset that's wrong; remove all together and you'll get 
the correct results:


$d = unpack('nth/Ntl/nfudge/nmac_size', $data);

Thanks, thought I had already tried that but obviously not.

Cheers

James

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php