Repository navigation
Reject empty HPACK header names - #3694
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What problem does this PR solve?
Issue Number: resolve N/A
Problem Summary:
The HPACK decoder accepts a zero-length literal header name, which RFC 7541 forbids.
DecodeString()returns the number of wire bytes consumed (1 for the0x00length octet), not the decoded string length, so the existingname_bytes <= 0check does not reject an empty name. The resultingHeader{name=""}is then passed toIndexTable::AddHeader(), whoseCHECK(!h.name.empty())aborts the process when the header uses incremental indexing. A malformed HEADERS frame can therefore terminate the server.What is changed and the side effects?
Changed:
HPacker::DecodeWithKnownPrefix()now rejects an empty decoded header name and returns -1, so malformed input is reported as a protocol error and the connection is closed instead of aborting the process.HPackTest.empty_header_namecovering literal header fields with incremental indexing, without indexing, never indexed, and a Huffman-encoded empty name.Side effects:
Performance effects: none; the new check runs once per literal header field with a decoded name.
Breaking backward compatibility: none for valid HPACK input, since an empty header name is invalid per RFC 7541.
Check List:
Tests run:
build/test/brpc_hpack_unittest --gtest_filter=HPackTest.empty_header_name(passes; fails/aborts without the fix)build/test/brpc_hpack_unittest(all other cases pass;many_dynamic_table_size_updatesfails before and after this change becausepthread_attr_setstacksize(64K)returns EINVAL in this environment)build/test/brpc_http_rpc_protocol_unittest --gtest_filter='*http2*:*h2_*'(23/23 pass)🤖 This PR was automatically created by brpc-oncall