Copilot commented on code in PR #3772:
URL: https://github.com/apache/brpc/pull/3772#discussion_r4663018738
##########
src/brpc/policy/http2_rpc_protocol.cpp:
##########
@@ -624,7 +644,21 @@ ParseResult H2Context::Consume(
LOG(ERROR) << "Invalid frame type=" << (int)frame_head.type;
return MakeParseError(PARSE_ERROR_ABSOLUTELY_WRONG);
}
- H2ParseResult h2_res = (this->*handler)(it, frame_head);
+ // A header block is decoded against the connection-wide HPACK
+ // context, so the frames carrying it have to arrive uninterrupted
+ // (RFC 9113 section 6.10). Without this, a CONTINUATION extends a
+ // header block that END_HEADERS already closed, and blocks of two
+ // streams can be decoded out of order.
+ H2ParseResult h2_res = CheckHeaderBlockContinuity(frame_head);
Review Comment:
`CheckHeaderBlockContinuity()` is reached only after `FindFrameHandler()`
succeeds. Therefore an unknown frame type received while
`_expect_continuation_stream_id` is set takes the earlier `handler == nullptr`
path and returns a generic parse error without sending the required
`GOAWAY(H2_PROTOCOL_ERROR)` for a non-CONTINUATION inside a header block. Run
the continuity check immediately after parsing the frame head, before handler
lookup, so the RFC 9113 ยง6.10 rule applies to unknown frame types as well.
##########
src/brpc/policy/http2_rpc_protocol.cpp:
##########
@@ -624,7 +644,21 @@ ParseResult H2Context::Consume(
LOG(ERROR) << "Invalid frame type=" << (int)frame_head.type;
return MakeParseError(PARSE_ERROR_ABSOLUTELY_WRONG);
}
- H2ParseResult h2_res = (this->*handler)(it, frame_head);
+ // A header block is decoded against the connection-wide HPACK
+ // context, so the frames carrying it have to arrive uninterrupted
+ // (RFC 9113 section 6.10). Without this, a CONTINUATION extends a
+ // header block that END_HEADERS already closed, and blocks of two
+ // streams can be decoded out of order.
+ H2ParseResult h2_res = CheckHeaderBlockContinuity(frame_head);
+ if (h2_res.is_ok()) {
+ if (frame_head.type == H2_FRAME_HEADERS ||
+ frame_head.type == H2_FRAME_CONTINUATION) {
+ _expect_continuation_stream_id =
+ (frame_head.flags & H2_FLAGS_END_HEADERS)
+ ? 0 : frame_head.stream_id;
+ }
+ h2_res = (this->*handler)(it, frame_head);
+ }
Review Comment:
The continuation state is published before the frame handler runs. A HEADERS
for a new stream can return a stream-scoped error without opening a stream (for
example, `TryToInsertStream()` returns `H2_REFUSED_STREAM` when the
concurrent-stream limit is reached), but this assignment still leaves that
stream ID in `_expect_continuation_stream_id`. `Consume()` then sends
RST_STREAM and continues parsing; the next valid frame on any other stream is
incorrectly rejected as a connection error because the parser is still waiting
for a CONTINUATION of the refused stream. Update the state after handling the
frame, clearing it whenever END_HEADERS is set, and only opening it for a
non-END_HEADERS frame when the handler succeeded.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]