php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31465 Warning: unpack(): Type H: outside of string
Submitted: 2005-01-10 05:07 UTC Modified: 2005-01-25 23:52 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:0 (0.0%)
From: php-bug-31247 at ryandesign dot com Assigned:
Status: Closed Package: Strings related
PHP Version: 4CVS, 5CVS (2005-01-10) OS: *
Private report: No CVE-ID:
 [2005-01-10 05:07 UTC] php-bug-31247 at ryandesign dot com
Description:
------------
I am experiencing the problem reported in bug 31247, 
which was marked as bogus. The decision was that the 
user's compiler was broken. I challenge this decision, 
as I see the problem with the (php.net-endorsed) 
precompiled Mac OS X version of PHP 5.0.3 (release 1) 
from www.entropy.ch and also with PHP 4.3.10 installed 
on a Gentoo server. I don't think all of these 
compilers are broken. I don't see the problem with 
Entropy PHP 4.3.9 (release 2) nor with 4.3.9 on a 
different Gentoo server.

I wonder whether the problem really relates to the 
break-statement-within-the-braces notation, because this 
notation is already present in PHP 4.3.9 which does not 
exhibit the problem. Regardless, I consider braces 
around cases within a switch to be poor form, and 
encourage developers I work with to not use it, as it 
gives the false impression to the uninitiated (which is 
often the person writing the code) that closing the 
brace closes the case (which of course it doesn't; the 
break actually does that).

Reproduce code:
---------------
php -r "print_r(unpack('H*hex', 'data'));"

Expected result:
----------------
Array
(
    [hex] => 64617461
)

Actual result:
--------------
Warning: unpack(): Type H: outside of string in Command 
line code on line 1
Array
(
    [hex] => 64617461
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-10 05:38 UTC] php-bug-31247 at ryandesign dot com
I've analyzed the PHP 5.0.3 source code and believe I 
have identified the problem. Here's my following of the 
logic in /etc/standard/pack.c, given an unpack string 
like "H*hex":

- On line 540, variable "inputpos" is set to 0.
- On line 564, since the format argument is "*",
  variable "arg" is set to -1.
- On line 601, variable "size" is set to the same value
  as "arg", so "size" is now -1.
- On line 832, "size" is added to "inputpos", so
  "inputpos" decreases by one and is now -1.
- On line 833, if "inputpos" is < 0 (which it is) an
  error is shown. This error display is one of the
  changes between PHP 4.3.9 and 5.0.3. This error
  display would seem to be what we're seeing in this
  case.
 [2005-01-21 01:31 UTC] phpbugrep-31465 at pgregg dot com
I concur with the submitters findings.
I've had the following script online for over a year and it has worked fine (without warnings) until 4.3.10 and 5.0.3 was released.... something changed in unpack to break it:
http://www.pgregg.com/projects/php/code/hexstr.phps

Warning is displayed at: http://www.pgregg.com/projects/php/code/hexstr.php
 [2005-01-25 23:52 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Fri Apr 18 15:02:26 2014 UTC