Skip to content

CURLE_WRITE_ERROR shadows CURLE_BAD_CONTENT_ENCODING #4310

Closed
@PersDep

Description

@PersDep

What is going on

curl_multi_info_read returns msg->data.result == CURLE_WRITE_ERROR if received Content-Encoding is not supported.

I expected the following

I expect curl_multi_info_read to return CURLE_BAD_CONTENT_ENCODING.

Code

if(!conn->data->set.http_te_skip && !k->ignorebody) {
    if(!conn->data->set.http_ce_skip && k->writer_stack)
        result = Curl_unencode_write(conn, k->writer_stack, datap, piece);
    else
        result = Curl_client_write(conn, CLIENTWRITE_BODY, datap, piece);

    if(result)
        return CHUNKE_WRITE_ERROR;
}

http_chunks.c 194-202

Curl_unencode_write returns CURLE_BAD_CONTENT_ENCODING and then it is being shadowed by CHUNKE_WRITE_ERROR which later is turning into CURLE_WRITE_ERROR.

curl/libcurl version

curl 7.65.3-DEV (x86_64-pc-linux-gnu) libcurl/7.65.3-DEV OpenSSL/1.1.1 zlib/1.2.11

operating system

Ubuntu 18.04.3 LTS

Activity

bagder

bagder commented on Sep 10, 2019

@bagder
Member

Do you have an example of how to reproduce this?

PersDep

PersDep commented on Sep 10, 2019

@PersDep
Author

Do you have an example of how to reproduce this?

Here is a test based on tests/libtest/lib597.c

#include "test.h"

#include <limits.h>

#include "testutil.h"
#include "warnless.h"
#include "memdebug.h"

#define TEST_HANG_TIMEOUT 5 * 1000

int test(char *URL)
{
  CURL *easy = NULL;
  CURLM *multi = NULL;
  int res = 0;
  int running;
  int msgs_left;
  CURLMsg *msg;

  start_test_timing();

  global_init(CURL_GLOBAL_ALL);

  easy_init(easy);

  multi_init(multi);

  /* go verbose */
  easy_setopt(easy, CURLOPT_VERBOSE, 1L);

  /* specify target */
  easy_setopt(easy, CURLOPT_URL, URL);

  /* ask for unsupported encoding */
  easy_setopt(easy, CURLOPT_ACCEPT_ENCODING, "br");

  multi_add_handle(multi, easy);

  for(;;) {
    struct timeval interval;
    fd_set fdread;
    fd_set fdwrite;
    fd_set fdexcep;
    long timeout = -99;
    int maxfd = -99;

    multi_perform(multi, &running);

    abort_on_test_timeout();

    if(!running)
      break; /* done */

    FD_ZERO(&fdread);
    FD_ZERO(&fdwrite);
    FD_ZERO(&fdexcep);

    multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);

    /* At this point, maxfd is guaranteed to be greater or equal than -1. */

    multi_timeout(multi, &timeout);

    /* At this point, timeout is guaranteed to be greater or equal than
       -1. */

    if(timeout != -1L) {
      int itimeout = (timeout > (long)INT_MAX) ? INT_MAX : (int)timeout;
      interval.tv_sec = itimeout/1000;
      interval.tv_usec = (itimeout%1000)*1000;
    }
    else {
      interval.tv_sec = TEST_HANG_TIMEOUT/1000 + 1;
      interval.tv_usec = 0;
    }

    select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &interval);

    abort_on_test_timeout();
  }

  msg = curl_multi_info_read(multi, &msgs_left);
  if(msg)
    res = msg->data.result;
  printf("RES: %d CURLE_WRITE_ERROR: %d\n", res, CURLE_WRITE_ERROR);

  multi_remove_handle(multi, easy);

test_cleanup:

  /* undocumented cleanup sequence - type UA */

  curl_multi_cleanup(multi);
  curl_easy_cleanup(easy);
  curl_global_cleanup();

  return res;
}

You can run it with URL == https://www.programcreek.com/python/example/103281/brotli.compress to see the described behavior. Also curl has to be configured with --without-brotli flag

bagder

bagder commented on Sep 10, 2019

@bagder
Member

Thank you, reproduced perfectly. Now I just need to figure out how to deal with this the best way...

self-assigned this
on Sep 13, 2019
bagder

bagder commented on Oct 1, 2019

@bagder
Member

Here's a stand alone version to repro: debug-4310.c

added a commit that references this issue on Oct 1, 2019
766a63a
locked as resolved and limited conversation to collaborators on Jan 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @bagder@PersDep

    Issue actions

      CURLE_WRITE_ERROR shadows CURLE_BAD_CONTENT_ENCODING · Issue #4310 · curl/curl