Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ext/standard/pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,9 @@ PHP_FUNCTION(unpack)

ZSTR_VAL(buf)[len] = '\0';

/* Advance by the number of bytes consumed, also for '*' */
size = (len + 1) / 2;

ZVAL_STR(&val, buf);
zend_symtable_update(Z_ARRVAL_P(return_value), real_name, &val);
break;
Expand Down
42 changes: 42 additions & 0 deletions ext/standard/tests/strings/unpack_hex_star_position.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
--TEST--
unpack() with "h*" and "H*" advances the position to the end of the input
--FILE--
<?php
var_dump(unpack("Ca/H*b/X/Cc", "\x01\xab\xcd"));
var_dump(unpack("Ca/h*b/X/Cc", "\x01\xab\xcd"));
var_dump(unpack("H*a/H*b", "\xab\xcd"));
var_dump(unpack("H*a/Cb", "\xab\xcd"));
var_dump(unpack("H3a/Cb", "\xab\xcd\xef"));
?>
--EXPECTF--
array(3) {
["a"]=>
int(1)
["b"]=>
string(4) "abcd"
["c"]=>
int(205)
}
array(3) {
["a"]=>
int(1)
["b"]=>
string(4) "badc"
["c"]=>
int(205)
}
array(2) {
["a"]=>
string(4) "abcd"
["b"]=>
string(0) ""
}

Warning: unpack(): Type C: not enough input values, need 1 values but only 0 were provided in %s on line %d
bool(false)
array(2) {
["a"]=>
string(3) "abc"
["b"]=>
int(239)
}
Loading