Repository navigation
fix(qpack): reject post-base references at or above Required Insert Count - #380
Open
prostomarkeloff wants to merge 1 commit into
Open
prostomarkeloff wants to merge 1 commit into
prostomarkeloff wants to merge 1 commit into
Conversation
…ount `VirtualAddressSpace::post_base` computed `base + index` without `checked_add` — both are peer-controlled prefix integers (up to ~2^63), so the sum can overflow and panic — and bounded the reference against the table's total inserted count rather than the block's Required Insert Count. RFC 9204 4.5.1 requires a reference whose absolute index is >= the declared Required Insert Count to be treated as QPACK_DECOMPRESSION_FAILED. Thread the Required Insert Count through DynamicTable::decoder into post_base (checked_add plus an `abs < required` ceiling) and relative_base, so an overflowing or out-of-window post-base index returns an error instead of panicking or decoding an entry the RFC requires to be rejected. Also fix decode_post_base_name_ref_header_field, which declared a Required Insert Count (2) smaller than the absolute index its post-base reference resolved to (3) — an RFC-invalid block that only decoded because of the missing check.
This branch has not been deployed
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.
Found with find-dup-defs using its
convergepass, which reports behavioural divergences between near-duplicate functions — here theVirtualAddressSpace::relative/relative_basepair, which led to the siblingpost_basenext to them.Problem
In
h3/src/qpack/vas.rs,VirtualAddressSpace::post_basevalidates a post-base reference like this:Two issues, both reachable from
Decoder::decode_headeron a peer-supplied header block:base + indexcan overflowusizeand panic.BaseisRequired Insert Count + Delta Base, and the post-base index is a prefix integer — both are read from the encoded block and can be ~2^63. Their sum overflows, which panics (attempt to add with overflow) in debug / with overflow-checks.The reference is bounded against the wrong quantity. It is compared to
self.inserted(everything the dynamic table has ever inserted) rather than the block's declared Required Insert Count. RFC 9204 §4.5.1:decode_headeronly checksrequired_ref <= total_inserted; the post-base path never compares against the Required Insert Count, so a block can reference an entry outside its declared window and still decode.Impact: a crafted header block can panic the decoder (DoS on untrusted input) or decode a reference the RFC requires to be rejected.
Fix
Thread the block's Required Insert Count (
required_ref) throughDynamicTable::decoder(base, required_ref)into the address space, and inpost_base:checked_addremoves the overflow; theabs < requiredceiling enforces §4.5.1.relative_basegains the same RFC bound (base - index > required→ error). Absolute indices here are 1-based, so the 0-basedabs < RICof the RFC isbase + index < requiredin these terms.A test was encoding an RFC-invalid block
decode_post_base_name_ref_header_fielddeclared Required Insert Count2while its post-base reference resolved to absolute index3— i.e. it referenced an entry beyond the count it declared, which §4.5.1 forbids. It only passed because of the missing check above. I raised its Required Insert Count to4(matching the siblingdecode_post_base_indexed) with an explanatory comment, so it exercises a conformant block.Tests
Two regression tests in
qpack::decoder::tests:repro_post_base_overflow(overflowing post-base index → error, no panic) andrepro_post_base_above_required_insert_count(absolute index ≥ RIC → error).cargo test -p h3 --lib qpackis green (135 passed).Disclosure: found and prepared with the help of an AI-assisted tool (a duplicate/divergence analyzer plus an LLM). I have reviewed the change and the tests, and can explain them.