]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
http_chunks: fix the accounting of consumed bytes
authorStefan Eissing <stefan@eissing.org>
Wed, 14 Feb 2024 15:27:23 +0000 (16:27 +0100)
committerJay Satiro <raysatiro@yahoo.com>
Sun, 18 Feb 2024 07:16:29 +0000 (02:16 -0500)
Prior to this change chunks were handled correctly although in verbose
mode libcurl could incorrectly warn of "Leftovers after chunking" even
if there were none.

Reported-by: Michael Kaufmann
Fixes https://github.com/curl/curl/issues/12937
Closes https://github.com/curl/curl/pull/12939

lib/http_chunks.c

index 039c179c44c09611ddbb576bfa28fa59f4ce98a2..ad1ee9adab67bb72be0d44688d66fed34d636741 100644 (file)
@@ -152,6 +152,7 @@ static CURLcode httpchunk_readwrite(struct Curl_easy *data,
         ch->hexbuffer[ch->hexindex++] = *buf;
         buf++;
         blen--;
+        (*pconsumed)++;
       }
       else {
         char *endptr;
@@ -189,6 +190,7 @@ static CURLcode httpchunk_readwrite(struct Curl_easy *data,
 
       buf++;
       blen--;
+      (*pconsumed)++;
       break;
 
     case CHUNK_DATA:
@@ -236,6 +238,7 @@ static CURLcode httpchunk_readwrite(struct Curl_easy *data,
       }
       buf++;
       blen--;
+      (*pconsumed)++;
       break;
 
     case CHUNK_TRAILER:
@@ -293,6 +296,7 @@ static CURLcode httpchunk_readwrite(struct Curl_easy *data,
       }
       buf++;
       blen--;
+      (*pconsumed)++;
       break;
 
     case CHUNK_TRAILER_CR:
@@ -300,6 +304,7 @@ static CURLcode httpchunk_readwrite(struct Curl_easy *data,
         ch->state = CHUNK_TRAILER_POSTCR;
         buf++;
         blen--;
+        (*pconsumed)++;
       }
       else {
         ch->state = CHUNK_FAILED;
@@ -320,6 +325,7 @@ static CURLcode httpchunk_readwrite(struct Curl_easy *data,
         /* skip if CR */
         buf++;
         blen--;
+        (*pconsumed)++;
       }
       /* now wait for the final LF */
       ch->state = CHUNK_STOP;
@@ -328,6 +334,7 @@ static CURLcode httpchunk_readwrite(struct Curl_easy *data,
     case CHUNK_STOP:
       if(*buf == 0x0a) {
         blen--;
+        (*pconsumed)++;
         /* Record the length of any data left in the end of the buffer
            even if there's no more chunks to read */
         ch->datasize = blen;