From: Nikita Popov Date: Sun, 8 Apr 2012 20:36:50 +0000 (+0200) Subject: Fix bug #61660: bin2hex(hex2bin($data)) != $data X-Git-Tag: php-5.4.4RC1~147 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7ae93a2c4c8a51cc2aec9977ce3c83c100e382a0;p=php Fix bug #61660: bin2hex(hex2bin($data)) != $data If the input data has an odd length a warning is thrown and false is returned. --- diff --git a/NEWS b/NEWS index 7b800840a0..42f7cd98ed 100644 --- 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) diff --git a/ext/standard/string.c b/ext/standard/string.c index 0aade78085..5c33232f7d 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -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 index 0000000000..010ea47e92 --- /dev/null +++ b/ext/standard/tests/strings/bug61660.phpt @@ -0,0 +1,11 @@ +--TEST-- +Bug #61660: bin2hex(hex2bin($data)) != $data +--FILE-- + +--EXPECTF-- +Warning: hex2bin(): Hexadecimal input string must have an even length in %s on line %d +bool(false)