Skip to content

reject zero-length padded DATA frame in H2Context::OnData#3325

Open
sahvx655-wq wants to merge 1 commit into
apache:masterfrom
sahvx655-wq:h2-data-pad-underflow
Open

reject zero-length padded DATA frame in H2Context::OnData#3325
sahvx655-wq wants to merge 1 commit into
apache:masterfrom
sahvx655-wq:h2-data-pad-underflow

Conversation

@sahvx655-wq
Copy link
Copy Markdown

A DATA frame with the PADDED flag but Length 0 underflows frag_size here. --frag_size wraps the uint32_t to 0xFFFFFFFF, the frag_size < pad_length check then passes, and the bogus size reaches append_and_forward, which swallows the rest of the connection buffer as one DATA payload and feeds ~4GiB into the flow-control counter. OnHeaders already rejects this case; OnData was missing the same guard. Fix returns FRAME_SIZE_ERROR per RFC 7540 6.1 when a padded frame has no room for the pad-length byte.

H2ParseResult H2Context::OnData(
butil::IOBufBytesIterator& it, const H2FrameHead& frame_head) {
const bool has_padding = (frame_head.flags & H2_FLAGS_PADDED);
if (frame_head.payload_size < (size_t)has_padding) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic is not clear to converter a bool to a size_t here

uint32_t frag_size = frame_head.payload_size;
uint8_t pad_length = 0;
if (frame_head.flags & H2_FLAGS_PADDED) {
if (has_padding) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a better way is to add the check code here:

if (frag_size <= 0) {
  LOG(ERROR) << ...
  return ...;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants