]> granicus.if.org Git - php/commitdiff
Fix bug #61660: bin2hex(hex2bin($data)) != $data
authorNikita Popov <nikic@php.net>
Sun, 8 Apr 2012 20:36:50 +0000 (22:36 +0200)
committerNikita Popov <nikic@php.net>
Sun, 8 Apr 2012 20:38:21 +0000 (22:38 +0200)
If the input data has an odd length a warning is thrown and false is returned.

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

diff --git a/NEWS b/NEWS
index 7b800840a001e4cc5846cacb84ba6a9932d4c2bf..42f7cd98ed8d46f150ebf0f5ec39dc1541cb8b12 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@ PHP                                                                        NEWS
   . "Connection: close" instead of "Connection: closed" (Gustavo)
 
 - Core:
+  . Fixed bug #61660 (bin2hex(hex2bin($data)) != $data). (Nikita Popov)
   . Fixed bug #61650 (ini parser crashes when using ${xxxx} ini variables
     (without apache2)). (Laruence)
   . Fixed bug #61605 (header_remove() does not remove all headers). (Laruence)
index 0aade780856b9a00ba606ba77028790f6d742b13..5c33232f7d7caa15eaa47832039f523041eb24fe 100644 (file)
@@ -266,6 +266,11 @@ PHP_FUNCTION(hex2bin)
                return;
        }
 
+       if (datalen % 2 != 0) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Hexadecimal input string must have an even length");
+               RETURN_FALSE;
+       }
+
        result = php_hex2bin((unsigned char *)data, datalen, &newlen);
 
        if (!result) {
diff --git a/ext/standard/tests/strings/bug61660.phpt b/ext/standard/tests/strings/bug61660.phpt
new file mode 100644 (file)
index 0000000..010ea47
--- /dev/null
@@ -0,0 +1,11 @@
+--TEST--
+Bug #61660: bin2hex(hex2bin($data)) != $data
+--FILE--
+<?php
+
+var_dump(hex2bin('123'));
+
+?>
+--EXPECTF--
+Warning: hex2bin(): Hexadecimal input string must have an even length in %s on line %d
+bool(false)