From:             ben dot ward at gmail dot com
Operating system: Red Hat
PHP version:      4.3.10
PHP Bug Type:     Unknown/Other Function
Bug description:  Type H: outside of string, error in ext/standard/pack.c

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

-- 
Edit bug report at http://bugs.php.net/?id=32142&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=32142&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=32142&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=32142&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=32142&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=32142&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=32142&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=32142&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=32142&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=32142&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=32142&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=32142&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=32142&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=32142&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=32142&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=32142&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=32142&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=32142&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=32142&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=32142&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=32142&r=mysqlcfg

Reply via email to