From 4d0c5c38a440fb172745cc2fbb6a782957314e8f Mon Sep 17 00:00:00 2001 From: Brian Neradt Date: Wed, 7 Aug 2024 11:51:58 -0500 Subject: [PATCH] multiplexer: fix consume of too many bytes (#11499) 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. (cherry picked from commit 6774984a3f71f7473092d1af7ba99a004e8890d9) --- iocore/eventsystem/P_IOBuffer.h | 1 + plugins/multiplexer/fetcher.h | 2 ++ 2 files changed, 3 insertions(+) diff --git a/iocore/eventsystem/P_IOBuffer.h b/iocore/eventsystem/P_IOBuffer.h index a3193b60b00..1448f9a0caf 100644 --- a/iocore/eventsystem/P_IOBuffer.h +++ b/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; diff --git a/plugins/multiplexer/fetcher.h b/plugins/multiplexer/fetcher.h index 45e892f2bac..fe236142645 100644 --- a/plugins/multiplexer/fetcher.h +++ b/plugins/multiplexer/fetcher.h @@ -211,6 +211,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) {