php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #61660
Patch hex2bin_padd_odd_new_patch revision 2012-04-08 09:18 UTC by theanomaly dot is at gmail dot com
Patch hex2bin_padd_odd revision 2012-04-08 04:33 UTC by theanomaly dot is at gmail dot com
Patch hex2bin_pad_odd_length.patch revision 2012-04-07 17:02 UTC by krtek4+php at gmail dot com

Patch hex2bin_padd_odd for *General Issues Bug #61660

Patch version 2012-04-08 04:33 UTC

Return to Bug #61660 | Download this patch
This patch is obsolete

Obsoleted by patches:

Patch Revisions:

Developer: theanomaly.is@gmail.com

diff --git a/ext/standard/string.c b/ext/standard/string.c
index 0aade78..8d046a4 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -150,6 +150,8 @@ static char *php_bin2hex(const unsigned char *old, const size_
  */
 static char *php_hex2bin(const unsigned char *old, const size_t oldlen, size_t *n
 {
+
+
        size_t target_length = oldlen >> 1;
        register unsigned char *str = (unsigned char *)safe_emalloc(target_length,
        size_t i, j;
@@ -266,6 +268,20 @@ PHP_FUNCTION(hex2bin)
                return;
        }
 
+       /* Fix for padding odd sized hex values to even length */
+       if (datalen % 2) {
+               datalen++;
+               char tmpdata[datalen+1];
+               int i;
+               tmpdata[0] = '0';               
+               for (i = 1; i < datalen; i++) {
+                       tmpdata[i] = data[i-1];
+               }
+               tmpdata[datalen] = '\0';
+               data = estrdup(tmpdata);
+       }       
+       /* End fix for odd sized hex values */
+
        result = php_hex2bin((unsigned char *)data, datalen, &newlen);
 
        if (!result) {

 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Wed Apr 23 07:02:14 2014 UTC