content_encoding: give a clear error on multi-member gzip

A gzip Content-Encoding response holding more than one gzip member made
curl decode the first member and then fail the transfer with a bare
CURLE_WRITE_ERROR and no hint about the cause. Detect the trailing
member and fail with a message that explains what happened.

Fixes #22156
Closes #22172
This commit is contained in:
HwangRock 2026-06-25 22:00:04 +09:00 committed by Daniel Stenberg
parent 2b5911880b
commit df350dd0d8
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
3 changed files with 70 additions and 1 deletions

View file

@ -206,6 +206,14 @@ static CURLcode inflate_stream(struct Curl_easy *data,
/* No more data to flush: exit loop. */
break;
case Z_STREAM_END:
if((started == ZLIB_INIT_GZIP) && (z->avail_in >= 2) &&
(z->next_in[0] == 0x1f) && (z->next_in[1] == 0x8b)) {
/* a second gzip member follows; curl does not support
multi-member gzip responses */
failf(data, "Multi-member gzip response not supported");
result = exit_zlib(data, z, &zp->zlib_init, CURLE_WRITE_ERROR);
break;
}
result = process_trailer(data, zp);
break;
case Z_DATA_ERROR:

View file

@ -259,7 +259,7 @@ test2108 test2109 test2113 \
test2200 test2201 test2202 test2203 test2204 test2205 test2206 test2207 \
test2208 \
\
test2300 test2301 test2302 test2303 test2304 test2306 test2307 test2308 \
test2300 test2301 test2302 test2303 test2304 test2305 test2306 test2307 test2308 \
test2309 test2310 test2311 \
\
test2400 test2401 test2402 test2403 test2404 test2405 test2406 test2407 \

61
tests/data/test2305 Normal file
View file

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="US-ASCII"?>
<testcase>
<info>
<keywords>
HTTP
HTTP GET
compressed
</keywords>
</info>
# Server-side
<reply>
<data nocheck="yes" crlf="headers">
HTTP/1.1 200 OK
Date: Mon, 29 Nov 2004 21:56:53 GMT
Server: test-server/fake
Content-Type: text/plain; charset=UTF-8
Content-Encoding: gzip
Content-Length: 54
%hex[%1f%8b%08%00%00%00%00%00%02%13%f3%48%cd%c9%c9%d7%51%00%00%05%6f%57%de%07%00%00%00%1f%8b%08%00%00%00%00%00%02%13%0b%cf%2f%ca%49%51%e4%02%00%dd%d1%ca%53%07%00%00%00]hex%
</data>
</reply>
# Client-side
<client>
<features>
libz
</features>
<server>
http
</server>
<name>
HTTP GET gzip compressed content with two concatenated gzip members
</name>
<command>
http://%HOSTIP:%HTTPPORT/%TESTNUMBER --compressed --silent --show-error
</command>
</client>
# Verify data after the test has been "shot"
<verify>
<strippart>
s/^Accept-Encoding: [a-zA-Z, ]*/Accept-Encoding: xxx/
</strippart>
<protocol crlf="headers">
GET /%TESTNUMBER HTTP/1.1
Host: %HOSTIP:%HTTPPORT
User-Agent: curl/%VERSION
Accept: */*
Accept-Encoding: xxx
</protocol>
<errorcode>
23
</errorcode>
<stderr mode="text">
curl: (23) Multi-member gzip response not supported
</stderr>
</verify>
</testcase>