]> granicus.if.org Git - php/commitdiff
MFH: Fixed bug #36148 (unpack("H*hex", $data) is adding an extra character
authorIlia Alshanetsky <iliaa@php.net>
Thu, 26 Jan 2006 15:47:31 +0000 (15:47 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Thu, 26 Jan 2006 15:47:31 +0000 (15:47 +0000)
to the end of the string).

NEWS
ext/standard/pack.c
ext/standard/tests/strings/bug36148.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index fe5d34adf9d57088949289630528098016f61fd4..8f8c450e142e34f5a0b8044ecec84cf9f89d8878 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,8 @@ PHP 4                                                                      NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2006, Version 4.4.3
 - Added a check for special characters in the session name. (Ilia)
+- Fixed bug #36148 (unpack("H*hex", $data) is adding an extra character to the 
+  end of the string). (Ilia)
 - Fixed bug #36017 (fopen() crashes PHP when opening a URL). (Tony)
 
 13 Jan 2006, Version 4.4.2
index fd9b1d23bccf5b2a112f07899ae864845a41d542..33a8e82fd6dc3a9523e03bbb140ad9f2ea9d4e3d 100644 (file)
@@ -693,7 +693,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 (file)
index 0000000..06caac3
--- /dev/null
@@ -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"
+}