|  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
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: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: php-bug-31247 at ryandesign dot com
New email:
PHP Version: OS:


 [2005-01-10 05:07 UTC] php-bug-31247 at ryandesign dot com
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 ( 
precompiled Mac OS X version of PHP 5.0.3 (release 1) 
from 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:
    [hex] => 64617461

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


Add a Patch

Pull Requests

Add a Pull Request


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
 [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:

Warning is displayed at:
 [2005-01-25 23:52 UTC]
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
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Thu Dec 07 03:01:28 2023 UTC