Sync shared HPack/QPack changes from aspnetcore#125526
Open
Conversation
…ow run 23059322485 Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
MihaZupan
March 13, 2026 16:51
View session
Member
|
Backport of dotnet/aspnetcore#65771 to runtime |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR closes a header-size enforcement gap in the shared HPack/QPack decoders by ensuring Huffman-decoded header names/values can’t exceed the configured maximum header length due to post-decode expansion.
Changes:
- Add post-Huffman-decode length validation in
HPackDecoderandQPackDecoder, throwing the appropriate decoding exception when the decoded length exceeds_maxHeadersLength. - Add debug assertions on the non-Huffman decode path documenting that the existing pre-decode length check is sufficient.
- Add new unit tests for HPack and QPack to cover Huffman inflation scenarios where encoded length is within the limit but decoded length exceeds it.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/libraries/Common/src/System/Net/Http/aspnetcore/Http2/Hpack/HPackDecoder.cs | Enforces _maxHeadersLength after Huffman decode to prevent inflated decoded strings from bypassing the limit. |
| src/libraries/Common/src/System/Net/Http/aspnetcore/Http3/QPack/QPackDecoder.cs | Mirrors the HPack fix for QPack by validating decoded length after Huffman decode. |
| src/libraries/Common/tests/Tests/System/Net/aspnetcore/Http2/HPackDecoderTest.cs | Adds regression tests that ensure oversized Huffman-decoded names/values throw and do not emit headers. |
| src/libraries/Common/tests/Tests/System/Net/aspnetcore/Http3/QPackDecoderTest.cs | Adds regression tests for the same Huffman expansion overflow scenario in QPack. |
You can also share your feedback on Copilot code review. Take the survey.
This was referenced Mar 14, 2026
Open
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.
Closes dotnet/aspnetcore#18943
Huffman-encoded strings can expand significantly on decode (e.g. 10 encoded bytes → 16 decoded bytes). Both
HPackDecoderandQPackDecodervalidated the encoded string length against_maxHeadersLengthbefore decoding, but never checked the decoded length — allowing Huffman-inflated headers to silently exceed the configured limit.Description
HPackDecoder: AfterHuffman.Decode, checkdecodedLength > _maxHeadersLengthand throwHPackDecodingException. AddDebug.Asserton the non-Huffman path confirming the pre-decode check is sufficient there.QPackDecoder: Same fix — post-decode length check throwingQPackDecodingException.HPackDecoderTest,QPackDecoderTest): Two new[Fact]tests each —HuffmanDecodedHeaderName_ExceedsLimitAfterDecoding_ThrowsandHuffmanDecodedHeaderValue_ExceedsLimitAfterDecoding_Throws— using amaxHeadersLength: 10decoder with a 10-byte Huffman payload that decodes to 16 bytes ('0'has a 5-bit code:00000).