#37234 [NEW]: unpack() hex problem
| From: | phpbug at drque dot net | Date: | Fri, 28 Apr 2006 08:46:07 +0000 |
| Subject: | #37234 [NEW]: unpack() hex problem | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-96318@lists.php.net to get a copy of this message | ||
From: phpbug at drque dot net
Operating system: Linux, Debian 2.6.8-3-k7
PHP version: 5.1.2
PHP Bug Type: Unknown/Other Function
Bug description: unpack() hex problem
Description:
------------
When unpacking hex with 'unpack', a "0" is appended to the end of the
resulting string. This did not happen in previous versions (this code
functions in PHP 5.1.1).
A quick fix can be done by commenting out line 695 in
"ext/standard/pack.c":
Change
len -= argb % 2;
to
//len -= argb % 2;
This line is one of 6 differences in "pack.c" between version 5.1.1 and
5.1.2. I wasn't able to understand why the "len -= argb %2" line was
added.
Reproduce code:
---------------
<?php
$HexString = 'c45dc988443fa8fff52ce7953bf049b8';
$PackedHexString = pack( "h*" , $HexString );
$UnpackedHex =
unpack( "h*Hex" , $PackedHexString );
$UnpackedHex = $UnpackedHex[ 'Hex' ];
echo "$HexString\n";
echo "$UnpackedHex\n";
?>
Expected result:
----------------
c45dc988443fa8fff52ce7953bf049b8
c45dc988443fa8fff52ce7953bf049b8
Actual result:
--------------
c45dc988443fa8fff52ce7953bf049b8
c45dc988443fa8fff52ce7953bf049b80
--
Edit bug report at http://bugs.php.net/?id=37234&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=37234&r=trysnapshot44
Try a CVS snapshot (PHP 5.1): http://bugs.php.net/fix.php?id=37234&r=trysnapshot51
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=37234&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=37234&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=37234&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=37234&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=37234&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=37234&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=37234&r=support
Expected behavior: http://bugs.php.net/fix.php?id=37234&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=37234&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=37234&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=37234&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=37234&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=37234&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=37234&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=37234&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=37234&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=37234&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=37234&r=mysqlcfg