Req #69947 [NEW]: hex2bin: allow odd-length string
| From: | marc at mabe dot berlin | Date: | Fri, 26 Jun 2015 21:24:49 +0000 |
| Subject: | Req #69947 [NEW]: hex2bin: allow odd-length string | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-193928@lists.php.net to get a copy of this message | ||
From: marc at mabe dot berlin
Operating system:
PHP version: 7.0Git-2015-06-26 (Git)
Package: *General Issues
Bug Type: Feature/Change Request
Bug description:hex2bin: allow odd-length string
Description:
------------
The current behavior on converting a hexadecimal string with an
odd-length into binary data results into a warning and returns false.
As the input is in hexadecimal notation it should be very valid to
remove "0" from the left.
This behavior is really annoying as it's not enough the check for valid
characters it's required to check the length, too.
Additionally within PHP itself the behavior is inconsistent:
bin2hex(hex2bin("123")) = Warning: hex2bin(): Hexadecimal input
string must have an even length
dechex(0x123) = "123"
base_convert(base_convert("123", 16, 2), 2, 16) = "123"
bin2hex(pack('H*', '123')) = "1230" (pack() will be part of another
bug report)
And on looking into JS and (My)SQL it's working well and can result in
an odd-length:
JavaScript:
parseInt("123", 16).toString(16) = "123"
MySQL:
SELECT HEX(UNHEX('123')) = "0123"
SELECT HEX(0x123) = "0123"
I have also found #61660 & #65155 where bin2hex(hex2bin("123")) was
resulting into "12" or false without any notice which was surly wrong
but simply adding a warning and returning false isn't a good fix in my
opinion.
Test script:
---------------
bin2hex(hex2bin("123"))
Expected result:
----------------
"0123"
Actual result:
--------------
Warning: hex2bin(): Hexadecimal input string must have an even length
--
Edit bug report at https://bugs.php.net/bug.php?id=69947&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69947&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69947&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69947&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69947&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69947&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69947&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69947&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69947&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69947&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69947&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69947&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69947&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69947&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69947&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69947&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69947&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69947&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69947&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69947&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69947&r=mysqlcfg