Bug #68225 [Opn]: unpack and X format code
Edit report at https://bugs.php.net/bug.php?id=68225&edit=1
ID: 68225
User updated by: mberchtold at gmail dot com
Reported by: mberchtold at gmail dot com
Summary: unpack and X format code
Status: Open
Type: Bug
Package: *General Issues
Operating System: Windows 64-bit
PHP Version: master-Git-2014-10-14 (snap)
Block user comment: N
Private report: N
New Comment:
Please disregard the comment regarding: "if (inputpos < size)"
I also would like to note that this happens with PHP 64-bit NTS.
Previous Comments:
------------------------------------------------------------------------
[2014-10-14 10:22:54] mberchtold at gmail dot com
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 this bug report at https://bugs.php.net/bug.php?id=68225&edit=1
Thread (3 messages)