Replace the function merge_chunks() in src/http.c with this one and let me know if this solves your problem.
static long merge_chunks(char *buffer, int size, long *bytes_in_buffer) {
int chunk_size, ch_len, len;
long content_length = 0;
char *end, *source, *destination;
source = buffer;
destination = buffer;
do {
if ((end = strstr(source, "\r\n")) == NULL) {
return -1;
}
*end = '\0';
chunk_size = hex_to_int(source);
*end = '\r';
if (chunk_size == -1) {
return -1;
}
ch_len = end - source + 2;
if (chunk_size == 0) {
if ((len = *bytes_in_buffer - ((end + 4) - buffer)) > 0) {
memmove(destination, end + 4, len);
*bytes_in_buffer -= (ch_len + 2);
}
*(buffer + *bytes_in_buffer) = '\0';
} else if (ch_len + chunk_size + 2 > size) {
return -1;
} else if (chunk_size > 0) {
memmove(destination, end + 2, chunk_size);
destination += chunk_size;
size -= (ch_len + chunk_size + 2);
source += (ch_len + chunk_size + 2);
content_length += chunk_size;
*bytes_in_buffer -= (ch_len + 2);
}
} while (chunk_size > 0);
return content_length;
}