summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlia Alshanetsky <iliaa@php.net>2006-01-26 15:45:33 +0000
committerIlia Alshanetsky <iliaa@php.net>2006-01-26 15:45:33 +0000
commitc5ef24bfeea1bfcb3a0f22d1dbb47586ad57a70b (patch)
treefdd65678d8f0c2cec3e7d6fec68564c5eaaf8af2
parent9eda552c75c744c42c3603eb5637e4bb32e01136 (diff)
downloadphp-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--NEWS2
-rw-r--r--ext/standard/pack.c4
-rw-r--r--ext/standard/tests/strings/bug36148.phpt29
3 files changed, 34 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index a4b84274c4..fe656b0f40 100644
--- a/NEWS
+++ b/NEWS
@@ -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"
+}