php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | |
Patch hex2bin_padd_odd for *General Issues Bug #61660Patch version 2012-04-08 04:33 UTC Return to Bug #61660 | Download this patchThis patch is obsolete Obsoleted by patches: Patch Revisions:Developer: theanomaly.is@gmail.comdiff --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) { |
Copyright © 2001-2024 The PHP Group All rights reserved. |
Last updated: Thu Nov 21 16:01:29 2024 UTC |