When a chunked message is sent and a new chunk is started in the zero-copy
path of h1_make_data(), the chunk size is taken from the <kop> hint of the
sedesc when it is set:
h1m->curr_len = (h1s->sd->kop ? h1s->sd->kop : count);
<kop> is the known output payload length, and by contract it is a minimal
guarantee: at least this size will be forwarded. When it is set, the H1 mux
announces it as the size of the chunk and consumes it. 0 means the output
payload length is unknown, and in this case only the size of the data block
is announced.
But nothing checked that the data sent with the chunk did not exceed the
announced size: h1m->curr_len was blindly decremented, possibly wrapping,
and the remaining bytes of the block were emitted without any chunk framing.
Such a violation could be observed when a data filter was used on the
request, before the previous patch fixed its root: the <kip> hint was
forwarded to <kop> on a stream not committed to forward its data, and a
stale value could then be announced for a data block, possibly smaller than
the block itself.
The copy path already reported an error for messages with a content-length
when more data than announced was met. The same check is now done in the
zero-copy path, for chunked messages: report an error and close the stream
instead of silently emitting an unframed payload. This is a guard for extra
safety, on top of the previous patch which fixes the issue at its root, in
the stream connectors.
Both patches must be backported as far as 3.3. On the stable branches, this
one must be applied on top of the other one, otherwise valid messages may be
rejected when a data filter alters the payload size and a stale <kip> hint
was moved to <kop>.
h1m->state = H1_MSG_DATA;
}
+ if (count > h1m->curr_len) {
+ COUNT("chunk bigger than announced (0-copy)");
+ TRACE_ERROR("chunk bigger than announced",
+ H1_EV_TX_DATA|H1_EV_STRM_ERR|H1_EV_H1C_ERR|H1_EV_H1S_ERR, h1c->conn, h1s);
+ goto error;
+ }
h1m->curr_len -= count;
/* It is the end of the chunk, append the CRLF */