diff options
author | Ilia Alshanetsky <iliaa@php.net> | 2005-12-28 20:56:22 +0000 |
---|---|---|
committer | Ilia Alshanetsky <iliaa@php.net> | 2005-12-28 20:56:22 +0000 |
commit | 821e0586df881bc6749b04d2f435ad50b0f5bb53 (patch) | |
tree | 80586f11c532459f102fb9746c96baefcfc20b2f /ext | |
parent | 9bcd09819ad3b51febca01bfcea40d5e8e0aaec4 (diff) | |
download | php-git-821e0586df881bc6749b04d2f435ad50b0f5bb53.tar.gz |
MFB51: Fixed bug #35817 (unpack() does not decode odd number of hexadecimal
values)
Diffstat (limited to 'ext')
-rw-r--r-- | ext/standard/pack.c | 9 | ||||
-rw-r--r-- | ext/standard/tests/strings/bug35817.phpt | 29 |
2 files changed, 35 insertions, 3 deletions
diff --git a/ext/standard/pack.c b/ext/standard/pack.c index 4b9ac02798..45ca0ec496 100644 --- a/ext/standard/pack.c +++ b/ext/standard/pack.c @@ -245,7 +245,7 @@ PHP_FUNCTION(pack) switch ((int) code) { case 'h': case 'H': - INC_OUTPUTPOS((arg + 1) / 2,1) /* 4 bit per arg */ + INC_OUTPUTPOS((arg + (arg % 2)) / 2,1) /* 4 bit per arg */ break; case 'a': @@ -538,7 +538,7 @@ PHP_FUNCTION(unpack) while (formatlen-- > 0) { char type = *(format++); char c; - int arg = 1; + int arg = 1, argb; char *name; int namelen; int size=0; @@ -563,6 +563,7 @@ PHP_FUNCTION(unpack) /* Get of new value in array */ name = format; + argb = arg; while (formatlen > 0 && *format != '/') { formatlen--; @@ -592,7 +593,7 @@ PHP_FUNCTION(unpack) case 'h': case 'H': - size = (arg > 0) ? arg / 2 : arg; + size = (arg > 0) ? (arg + (arg % 2)) / 2 : arg; arg = 1; break; @@ -691,6 +692,8 @@ PHP_FUNCTION(unpack) len = size * 2; } + len -= argb % 2; + buf = emalloc(len + 1); for (ipos = opos = 0; opos < len; opos++) { diff --git a/ext/standard/tests/strings/bug35817.phpt b/ext/standard/tests/strings/bug35817.phpt new file mode 100644 index 0000000000..e2a752c4ab --- /dev/null +++ b/ext/standard/tests/strings/bug35817.phpt @@ -0,0 +1,29 @@ +--TEST-- +Bug #35817 (unpack() does not decode odd number of hexadecimal values) +--FILE-- +<?php +$a = pack("H3","181"); +$b = unpack("H3", $a); +var_dump($b); + +$a = pack("H2","18"); +$b = unpack("H2", $a); +var_dump($b); + +$a = pack("H","1"); +$b = unpack("H", $a); +var_dump($b); +?> +--EXPECT-- +array(1) { + [1]=> + string(3) "181" +} +array(1) { + [1]=> + string(2) "18" +} +array(1) { + [1]=> + string(1) "1" +} |