diff options
| author | Ilia Alshanetsky <iliaa@php.net> | 2006-01-26 15:45:33 +0000 |
|---|---|---|
| committer | Ilia Alshanetsky <iliaa@php.net> | 2006-01-26 15:45:33 +0000 |
| commit | c5ef24bfeea1bfcb3a0f22d1dbb47586ad57a70b (patch) | |
| tree | fdd65678d8f0c2cec3e7d6fec68564c5eaaf8af2 | |
| parent | 9eda552c75c744c42c3603eb5637e4bb32e01136 (diff) | |
| download | php-git-c5ef24bfeea1bfcb3a0f22d1dbb47586ad57a70b.tar.gz | |
Fixed bug #36148 (unpack("H*hex", $data) is adding an extra character to the
end of the string).
| -rw-r--r-- | NEWS | 2 | ||||
| -rw-r--r-- | ext/standard/pack.c | 4 | ||||
| -rw-r--r-- | ext/standard/tests/strings/bug36148.phpt | 29 |
3 files changed, 34 insertions, 1 deletions
@@ -15,6 +15,8 @@ PHP NEWS - Fixed imagecolorallocate() and imagecolorallocatelapha() to return FALSE on error. (Pierre) - Fixed bug #36152 (problems with curl+ssl and pgsql+ssl in same PHP). (Mike) +- Fixed bug #36148 (unpack("H*hex", $data) is adding an extra character to the + end of the string). (Ilia) - Fixed bug #36134 (DirectoryIterator constructor failed to detect empty directory names). (Ilia) - Fixed bug #36113 (Reading records of unsupported type causes segfault). diff --git a/ext/standard/pack.c b/ext/standard/pack.c index 209ddf8de0..f088890a59 100644 --- a/ext/standard/pack.c +++ b/ext/standard/pack.c @@ -692,7 +692,9 @@ PHP_FUNCTION(unpack) len = size * 2; } - len -= argb % 2; + if (argb > 0) { + len -= argb % 2; + } buf = emalloc(len + 1); diff --git a/ext/standard/tests/strings/bug36148.phpt b/ext/standard/tests/strings/bug36148.phpt new file mode 100644 index 0000000000..06caac3334 --- /dev/null +++ b/ext/standard/tests/strings/bug36148.phpt @@ -0,0 +1,29 @@ +--TEST-- +Bug #36148 (unpack("H*hex", $data) is adding an extra character to the end of the string) +--FILE-- +<?php +$values = array("a", "aa", "aaa", "aaaa"); +foreach ($values as $value) { + $a = pack("H*", $value); + $b = unpack("H*", $a); + echo $value.": "; + var_dump($b); +} +?> +--EXPECT-- +a: array(1) { + [1]=> + string(2) "a0" +} +aa: array(1) { + [1]=> + string(2) "aa" +} +aaa: array(1) { + [1]=> + string(4) "aaa0" +} +aaaa: array(1) { + [1]=> + string(4) "aaaa" +} |
