php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37234 unpack() hex problem
Submitted: 2006-04-28 08:46 UTC Modified: 2006-05-01 13:46 UTC
From: phpbug at drque dot net Assigned:
Status: Closed Package: Unknown/Other Function
PHP Version: 5.1.2 OS: Linux, Debian 2.6.8-3-k7
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: phpbug at drque dot net
New email:
PHP Version: OS:

 

 [2006-04-28 08:46 UTC] phpbug at drque dot net
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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-29 11:27 UTC] mike@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.1-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.1-win32-latest.zip

Looks fine in 5.1.3.
 [2006-05-01 13:46 UTC] phpbug at drque dot net
PHP 5.1-200605011230 does work fine.  Seems the area in question in "ext/standard/pack.c" has been changed to:
   if (argb > 0) {	
     len -= argb % 2;
   }

Thank you Mike
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC