Skip to content

Commit c8fbe07

Browse files
committed
fixed unpack()
1 parent 2d44a04 commit c8fbe07

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

ext/standard/pack.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -529,9 +529,9 @@ static long php_unpack(char *data, zend_str_size_int size, int issigned, int *ma
529529
PHP_FUNCTION(unpack)
530530
{
531531
char *format, *input, *formatarg, *inputarg;
532-
int formatlen;
533532
zend_str_size_int formatarg_len, inputarg_len;
534-
int inputpos, inputlen, i;
533+
zend_str_size_int formatlen, inputpos, inputlen;
534+
int i;
535535

536536
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS", &formatarg, &formatarg_len,
537537
&inputarg, &inputarg_len) == FAILURE) {
@@ -551,8 +551,8 @@ PHP_FUNCTION(unpack)
551551
char c;
552552
int arg = 1, argb;
553553
char *name;
554-
zend_str_size_int namelen;
555-
zend_str_size_int size=0;
554+
int namelen;
555+
int size=0;
556556

557557
/* Handle format arguments if any */
558558
if (formatlen > 0) {
@@ -673,7 +673,7 @@ PHP_FUNCTION(unpack)
673673
inputpos = 0;
674674
}
675675

676-
if ((inputpos + size) <= inputlen) {
676+
if ((size >=0 && (inputpos + size) <= inputlen) || (size < 0 && -size <= (inputlen - inputpos))) {
677677
switch ((int) type) {
678678
case 'a': {
679679
/* a will not strip any trailing whitespace or null padding */
@@ -920,8 +920,10 @@ PHP_FUNCTION(unpack)
920920
}
921921
}
922922

923-
formatlen--; /* Skip '/' separator, does no harm if inputlen == 0 */
924-
format++;
923+
if (formatlen > 0) {
924+
formatlen--; /* Skip '/' separator, does no harm if inputlen == 0 */
925+
format++;
926+
}
925927
}
926928
}
927929
/* }}} */

0 commit comments

Comments
 (0)