Skip to content

Commit

Permalink
chunked decoding, fix accounting
Browse files Browse the repository at this point in the history
- refs curl#12937
- chunks were handled correctly, but accounting was
  borked so that "left" bytes were reported on the
  last chunk written.
  • Loading branch information
icing committed Feb 14, 2024
1 parent 5691a6c commit 5ac5065
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/http_chunks.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ static CURLcode httpchunk_readwrite(struct Curl_easy *data,
ch->hexbuffer[ch->hexindex++] = *buf;
buf++;
blen--;
(*pconsumed)++;
}
else {
char *endptr;
Expand Down Expand Up @@ -189,6 +190,7 @@ static CURLcode httpchunk_readwrite(struct Curl_easy *data,

buf++;
blen--;
(*pconsumed)++;
break;

case CHUNK_DATA:
Expand Down Expand Up @@ -236,6 +238,7 @@ static CURLcode httpchunk_readwrite(struct Curl_easy *data,
}
buf++;
blen--;
(*pconsumed)++;
break;

case CHUNK_TRAILER:
Expand Down Expand Up @@ -293,13 +296,15 @@ static CURLcode httpchunk_readwrite(struct Curl_easy *data,
}
buf++;
blen--;
(*pconsumed)++;
break;

case CHUNK_TRAILER_CR:
if(*buf == 0x0a) {
ch->state = CHUNK_TRAILER_POSTCR;
buf++;
blen--;
(*pconsumed)++;
}
else {
ch->state = CHUNK_FAILED;
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 5ac5065

Please sign in to comment.