Skip to content

Commit 7ae93a2

Browse files
committed
Fix bug #61660: bin2hex(hex2bin($data)) != $data
If the input data has an odd length a warning is thrown and false is returned.
1 parent f7d4076 commit 7ae93a2

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ PHP NEWS
99
. "Connection: close" instead of "Connection: closed" (Gustavo)
1010

1111
- Core:
12+
. Fixed bug #61660 (bin2hex(hex2bin($data)) != $data). (Nikita Popov)
1213
. Fixed bug #61650 (ini parser crashes when using ${xxxx} ini variables
1314
(without apache2)). (Laruence)
1415
. Fixed bug #61605 (header_remove() does not remove all headers). (Laruence)

ext/standard/string.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,11 @@ PHP_FUNCTION(hex2bin)
266266
return;
267267
}
268268

269+
if (datalen % 2 != 0) {
270+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Hexadecimal input string must have an even length");
271+
RETURN_FALSE;
272+
}
273+
269274
result = php_hex2bin((unsigned char *)data, datalen, &newlen);
270275

271276
if (!result) {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
Bug #61660: bin2hex(hex2bin($data)) != $data
3+
--FILE--
4+
<?php
5+
6+
var_dump(hex2bin('123'));
7+
8+
?>
9+
--EXPECTF--
10+
Warning: hex2bin(): Hexadecimal input string must have an even length in %s on line %d
11+
bool(false)

0 commit comments

Comments
 (0)