Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/common/http/http2/codec_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ class ConnectionImpl : public virtual Connection,
const StreamInfo::BytesMeterSharedPtr& bytesMeter() override { return bytes_meter_; }
ConnectionImpl& parent_;
int32_t stream_id_{-1};
uint32_t unconsumed_bytes_{0};
uint64_t unconsumed_bytes_{0};
uint32_t read_disable_count_{0};
StreamInfo::BytesMeterSharedPtr bytes_meter_{std::make_shared<StreamInfo::BytesMeter>()};

Expand Down
22 changes: 22 additions & 0 deletions test/common/http/http2/codec_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2595,6 +2595,28 @@ TEST_P(Http2CodecImplFlowControlTest, RstStreamOnPendingFlushTimeoutFlood) {
EXPECT_EQ(1, server_stats_store_.counter("http2.outbound_flood").value());
}

// Verify that unconsumed_bytes_ is 64-bit and does not overflow.
TEST_P(Http2CodecImplFlowControlTest, UnconsumedBytesOverflowPrevention) {
initialize();

TestRequestHeaderMapImpl request_headers;
HttpTestUtility::addDefaultHeaders(request_headers);
EXPECT_TRUE(request_encoder_->encodeHeaders(request_headers, false).ok());
driveToCompletion();

auto* stream = server_->getStream(1);
ASSERT_NE(stream, nullptr);

// Directly set unconsumed_bytes_ to a value close to UINT32_MAX.
stream->unconsumed_bytes_ = static_cast<uint64_t>(UINT32_MAX) - 100;

// Add more bytes to simulate receiving data while read-disabled.
stream->unconsumed_bytes_ += 200;

// Verify that it has successfully held a value larger than UINT32_MAX without overflow/wrap-around.
EXPECT_EQ(stream->unconsumed_bytes_, static_cast<uint64_t>(UINT32_MAX) + 100);
}

TEST_P(Http2CodecImplTest, WatermarkUnderEndStream) {
initialize();
MockStreamCallbacks callbacks;
Expand Down