]> granicus.if.org Git - php/commitdiff
Fixed bug #36148 (unpack("H*hex", $data) is adding an extra character to the
authorIlia Alshanetsky <iliaa@php.net>
Thu, 26 Jan 2006 15:45:33 +0000 (15:45 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Thu, 26 Jan 2006 15:45:33 +0000 (15:45 +0000)
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 a4b84274c461279d353036cb90415dfc899bcc85..fe656b0f40715ebb47efa9a0050988c58390c0ba 100644 (file)
--- 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). 
index 209ddf8de0cf275eb72f8f01151390988322b3e0..f088890a59a8635ac388089de4a820ef723c7eed 100644 (file)
@@ -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 (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"
+}