Skip to content

Bug fix for bugid #61660 including test in ext/standard/strings/61660.phpt #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion ext/standard/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,20 @@ static char *php_bin2hex(const unsigned char *old, const size_t oldlen, size_t *
static char *php_hex2bin(const unsigned char *old, const size_t oldlen, size_t *newlen)
{
size_t target_length = oldlen >> 1;
int e;
e = oldlen & 1;
if (e) {
target_length++;
}
register unsigned char *str = (unsigned char *)safe_emalloc(target_length, sizeof(char), 1);
size_t i, j;
for (i = j = 0; i < target_length; i++) {
char c = old[j++];
char c = '0';
if (j == 0 && e) {
c = '0';
} else {
c = old[j++];
}
if (c >= '0' && c <= '9') {
str[i] = (c - '0') << 4;
} else if (c >= 'a' && c <= 'f') {
Expand Down