php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32142 Type H: outside of string, error in ext/standard/pack.c
Submitted: 2005-03-01 01:17 UTC Modified: 2005-03-01 01:40 UTC
From: ben dot ward at gmail dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: 4.3.10 OS: Red Hat
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ben dot ward at gmail dot com
New email:
PHP Version: OS:

 

 [2005-03-01 01:17 UTC] ben dot ward at gmail dot com
Description:
------------
See bug #31247
I've got a similar problem only I'm using 4.1.2, and phpinfo reports "Linux tweety.build.redhat.com 2.6.9-1.906_ELsmp #1 SMP Sun Dec 12 22:58:08 EST 2004 i686 unknown"
This code used to work before our sysadmin patched the server:
$packet = unpack("H*", $packet);
after the patch I got the same warning "Type H: outside of string"
I downloaded the source to 4.3.10 and discovered that due to the way it's written, H* will generate that warning and abort early.
here is a workaround for the same code fragment
$packet = unpack("H".(strlen($packet) * 2), $packet);
$packet[""] = $packet[1];
unset($packet[1]);
the problem isn't with the curly braces on the case, it's with the size variable and this if *after* the switch
				inputpos += size;
				if (inputpos < 0) {
					php_error_docref(NULL TSRMLS_CC, E_WARNING, "Type %c: outside of string", type);
					inputpos = 0;
				}


when this piece of code is hit with "H*" inputpos = 0, and size = -1 because H is the first specifier, and size is set to -1 to represent * in this piece of code
			case 'H': 
				size = (arg > 0) ? arg / 2 : arg;
				arg = 1;
				break;
If I get time this weekend I'll post a fix, hope this helps
Thanks,
Ben M. Ward
ps the source file I downloaded was http://us4.php.net/distributions/php-4.3.10.tar.gz  and the source file I walked through was php-4.3.10/ext/standard/pack.c function PHP_FUNCTION(unpack)

Reproduce code:
---------------
<?php
echo unpack("H*", "ABCD");
?>

Expected result:
----------------
41424344

Actual result:
--------------
Warning: Type H: outside of string in /var/www/tsadmind/development/test.php on line 2
Array

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-03-01 01:40 UTC] sniper@php.net
I'd be very worried if that output anything else that 'Array', 
perhaps you should try this with latest snapshot:

# sapi/cli/php -r 'var_dump(unpack("H*", "ABCD"));'

Where it works just fine. (hint: try search next time before reporting same issue: See bug #31465)

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 11:01:30 2024 UTC