Skip to content

Commit 8ac56c1

Browse files
committed
Merge branch 'PHP-5.4'
* PHP-5.4: Fix bug #61660: bin2hex(hex2bin($data)) != $data
2 parents bd5f52f + 7ae93a2 commit 8ac56c1

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

Diff for: ext/standard/string.c

+5
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) {

Diff for: ext/standard/tests/strings/bug61660.phpt

+11
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)