On Mon, Apr 9, 2012 at 4:36 AM, Nikita Popov <ni...@php.net> wrote:
> Commit:    7ae93a2c4c8a51cc2aec9977ce3c83c100e382a0
> Author:    Nikita Popov <ni...@php.net>         Sun, 8 Apr 2012 22:36:50 +0200
> Parents:   f7d407678570f8e4063b70bd30f3fc19c10442ea
> Branches:  PHP-5.4 master
>
> Link:       
> http://git.php.net/?p=php-src.git;a=commitdiff;h=7ae93a2c4c8a51cc2aec9977ce3c83c100e382a0
>
> Log:
> Fix bug #61660: bin2hex(hex2bin($data)) != $data
>
> If the input data has an odd length a warning is thrown and false is returned.
>
> Bugs:
> https://bugs.php.net/61660
>
> Changed paths:
>  M  NEWS
>  M  ext/standard/string.c
>  A  ext/standard/tests/strings/bug61660.phpt
>
>
> Diff:
> diff --git a/NEWS b/NEWS
> index 7b80084..42f7cd9 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 0aade78..5c33232 100644
> --- a/ext/standard/string.c
> +++ b/ext/standard/string.c
> @@ -266,6 +266,11 @@ PHP_FUNCTION(hex2bin)
>                return;
>        }
>
> +       if (datalen % 2 != 0) {
Hi:
    I prefer to use datalen & 1, but up to you  :)

thanks
> +               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 0000000..010ea47
> --- /dev/null
> +++ b/ext/standard/tests/strings/bug61660.phpt
> @@ -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)
>
>
> --
> PHP CVS Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>



-- 
Laruence  Xinchen Hui
http://www.laruence.com/

--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to