Hi All,
When trying libcurl 8.18.0 in our application, I noticed that
curl_easy_setopt() returns CURLE_OUT_OF_MEMORY for CURLOPT_ACCEPT_ENCODING
option with “” value (all available)
libcurl was built without compression libraries (zlib etc).
curl_easy_setopt(easy, CURLOPT_ACCEPT_ENCODING, ""); // returns
CURLE_OUT_OF_MEMORY
The previous releases (i.e. 8.6.0) returned CURLE_OK, and the performed
transfers had "Accept-Encoding: identity" header.
I looked into the code and the issue is in the following code in \lib\setopt.c
case CURLOPT_ACCEPT_ENCODING:
...
if(ptr && !*ptr) {
ptr = Curl_get_content_encodings();
if(ptr) {
curlx_free(s->str[STRING_ENCODING]);
s->str[STRING_ENCODING] = ptr;
}
else
result = CURLE_OUT_OF_MEMORY;
return result;
}
return Curl_setstropt(&s->str[STRING_ENCODING], ptr);
The problem is that the Curl_get_content_encodings() function returns NULL if
libcurl is built without compression libraries because it skips over the
CONTENT_ENCODING_DEFAULT("identity"),
If we look into the Curl_get_content_encodings() code:
char *Curl_get_content_encodings(void)
{
struct dynbuf enc;
const struct Curl_cwtype * const *cep;
CURLcode result = CURLE_OK;
curlx_dyn_init(&enc, 255);
for(cep = general_unencoders; *cep && !result; cep++) {
const struct Curl_cwtype *ce = *cep;
if(!curl_strequal(ce->name, CONTENT_ENCODING_DEFAULT)) {
if(curlx_dyn_len(&enc))
result = curlx_dyn_addn(&enc, ", ", 2);
if(!result)
result = curlx_dyn_add(&enc, ce->name);
}
}
if(!result)
return curlx_dyn_ptr(&enc);
return NULL;
}
we will see that if the general_unencoders contains only " identity", then the
curlx_dyn_ptr(&enc) will return NULL.
To fix the problem, we need to add "identity" to the enc buffer if no encoding
strings were added to it in the for-loop, like:
if(!result) {
if (!enc.bufr)
curlx_dyn_add(&enc, CONTENT_ENCODING_DEFAULT);
return curlx_dyn_ptr(&enc);
}
Thanks,
Dmitry Karpov
--
Unsubscribe: https://lists.haxx.se/mailman/listinfo/curl-library
Etiquette: https://curl.se/mail/etiquette.html