Skip to content

Commit e7a6c15

Browse files
committed
Fixed bug #68225 unpack and X format code
This is done by reverting some parts to the state of pre 7, whereby that means all the size_t potential isn't exhausted. This might be a subject of the subsequent fix, the functionality can be ensured with the supplied test.
1 parent dcfe587 commit e7a6c15

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

ext/standard/pack.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ PHP_FUNCTION(unpack)
560560
{
561561
char *format, *input;
562562
zend_string *formatarg, *inputarg;
563-
size_t formatlen, inputpos, inputlen;
563+
zend_long formatlen, inputpos, inputlen;
564564
int i;
565565

566566
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS", &formatarg,
@@ -717,7 +717,7 @@ PHP_FUNCTION(unpack)
717717
inputpos = 0;
718718
}
719719

720-
if ((size >=0 && (inputpos + size) <= inputlen) || (size < 0 && -size <= (inputlen - inputpos))) {
720+
if ((inputpos + size) <= inputlen) {
721721
switch ((int) type) {
722722
case 'a': {
723723
/* a will not strip any trailing whitespace or null padding */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
Bug #68225 unpack and X format code
3+
--FILE--
4+
<?php
5+
6+
$data = pack('VV', 1, 2);
7+
8+
$result = unpack('Va/X' ,$data);
9+
var_dump($result);
10+
11+
$result = unpack('Va/X4' ,$data);
12+
var_dump($result);
13+
14+
$result = unpack('V1a/X4/V1b/V1c/X4/V1d', $data);
15+
var_dump($result);
16+
17+
?>
18+
===DONE===
19+
--EXPECTF--
20+
array(1) {
21+
["a"]=>
22+
int(1)
23+
}
24+
array(1) {
25+
["a"]=>
26+
int(1)
27+
}
28+
array(4) {
29+
["a"]=>
30+
int(1)
31+
["b"]=>
32+
int(1)
33+
["c"]=>
34+
int(2)
35+
["d"]=>
36+
int(2)
37+
}
38+
===DONE===
39+

0 commit comments

Comments
 (0)