Bug #68225 [NEW]: unpack and X format code
From: mberchtold at gmail dot com
Operating system: Windows 64-bit
PHP version: master-Git-2014-10-14 (snap)
Package: *General Issues
Bug Type: Bug
Bug description:unpack and X format code
Description:
------------
unpack with the X format code is broken.
There are 2 related issues:
1. Unexpected warning
PHP Warning: unpack(): Type X: outside of string
The bug is here:
File: php-src / ext / standard / pack.c
In the following snipped size is -1 for the X format code, therefore the
first condition if (inputpos < size) is always true.
case 'X':
if (inputpos < size) {
inputpos = -size;
i = arg - 1; /* Break out of for loop */
if (arg >= 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Type %c: outside of
string", type);
}
}
break;
2. unpack returns false and additional warning:
HP Warning: unpack(): Type X: not enough input, need -1, have 0
Test script:
---------------
<?php
$data = pack('VV', 1, 2);
$result = unpack('Va/X' ,$data);
// PHP Warning: unpack(): Type X: outside of string
$result = unpack('Va/X4' ,$data);
// PHP Warning: unpack(): Type X: outside of string
$result = unpack('V1a/X4/V1b/V1c/X4/V1d', $data);
// PHP Warning: unpack(): Type X: outside of string
// PHP Warning: unpack(): Type X: not enough input, need -1, have 0
// unpack returns false
var_dump($result);
?>
Expected result:
----------------
No warnings.
No failures
Actual result:
--------------
Warnings:
PHP Warning: unpack(): Type X: outside of string
PHP Warning: unpack(): Type X: not enough input, need -1, have 0
And wrong result.
--
Edit bug report at https://bugs.php.net/bug.php?id=68225&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=68225&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=68225&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=68225&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=68225&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=68225&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=68225&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=68225&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=68225&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=68225&r=support
Expected behavior: https://bugs.php.net/fix.php?id=68225&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=68225&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=68225&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=68225&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68225&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=68225&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=68225&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=68225&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=68225&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=68225&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=68225&r=mysqlcfg
Thread (3 messages)
- mberchtold at gmail dot com