Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix bug #61660: bin2hex(hex2bin($data)) != $data

If the input data has an odd length a warning is thrown and false is returned.
  • Loading branch information...
commit 7ae93a2c4c8a51cc2aec9977ce3c83c100e382a0 1 parent f7d4076
Nikita Popov nikic authored
1  NEWS
View
@@ -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)
5 ext/standard/string.c
View
@@ -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) {
11 ext/standard/tests/strings/bug61660.phpt
View
@@ -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)

1 comment on commit 7ae93a2

Stanislav Malyshev
Owner

I don't think it is a good idea to put this BC-breaking patch into 5.4.

Please sign in to comment.
Something went wrong with that request. Please try again.