From cf084bebfb873a2bee62d7bc15a62508893f94d1 Mon Sep 17 00:00:00 2001 From: Brian Neradt Date: Mon, 1 Jul 2024 22:41:43 +0000 Subject: [PATCH] multiplexer: fix consume of too many bytes IOBufferReader::consume contractually assumes that all callers of it will not consume more bytes than read_avail for the buffer chain. This adds a debug assertion for this and fixes multiplexer so that it doesn't violate this invariant. --- plugins/multiplexer/fetcher.h | 2 ++ src/iocore/eventsystem/P_IOBuffer.h | 1 + 2 files changed, 3 insertions(+) diff --git a/plugins/multiplexer/fetcher.h b/plugins/multiplexer/fetcher.h index a1a249187c5..6a51928b2d4 100644 --- a/plugins/multiplexer/fetcher.h +++ b/plugins/multiplexer/fetcher.h @@ -213,6 +213,8 @@ template struct HttpTransaction { self->t_.header(self->parser_.buffer_, self->parser_.location_); self->parsingHeaders_ = false; } + // Parsing headers will indirectly read from our reader. Update available accordingly. + available = TSIOBufferReaderAvail(self->in_->reader); } if (!self->parsingHeaders_) { if (self->chunkDecoder_ != NULL) { diff --git a/src/iocore/eventsystem/P_IOBuffer.h b/src/iocore/eventsystem/P_IOBuffer.h index 7be6569d75f..4613d17af84 100644 --- a/src/iocore/eventsystem/P_IOBuffer.h +++ b/src/iocore/eventsystem/P_IOBuffer.h @@ -551,6 +551,7 @@ IOBufferReader::is_read_avail_more_than(int64_t size) TS_INLINE void IOBufferReader::consume(int64_t n) { + ink_assert(read_avail() >= n); start_offset += n; if (size_limit != INT64_MAX) { size_limit -= n;