maskit commented on code in PR #14019:
URL: https://github.com/apache/trafficserver/pull/14019#discussion_r4528823082
##########
src/proxy/http3/QPACK.cc:
##########
@@ -1123,17 +1199,21 @@ QPACK::_decode_header(const uint8_t *header_block,
size_t header_block_len, HTTP
}
void
-QPACK::_decode(EThread *ethread, Continuation *cont, uint64_t stream_id, const
uint8_t *header_block, size_t header_block_len,
- HTTPHdr &hdr)
+QPACK::_decode(EThread *ethread, Continuation *cont, uint64_t stream_id,
uint32_t required_insert_count,
+ const uint8_t *header_block, size_t header_block_len, HTTPHdr
&hdr)
{
int event;
- int res = this->_decode_header(header_block, header_block_len, hdr);
+ int res = this->_decode_header(required_insert_count, header_block,
header_block_len, hdr);
if (res < 0) {
event = QPACK_EVENT_DECODE_FAILED;
QPACKDebug("decoding header failed (%d)", res);
} else {
event = QPACK_EVENT_DECODE_COMPLETE;
- this->_write_header_acknowledgement(stream_id);
+ // Only a block that references the dynamic table is acknowledged (RFC
9204 Section 4.4.1). The encoder tracks nothing for
+ // the others, and treats an acknowledgement it has nothing outstanding
for as an error.
+ if (required_insert_count != 0) {
Review Comment:
Sending the Section Acknowledgment unconditionally still passes every test.
Could you add a check that a block with a Required Insert Count of 0 writes
nothing to the decoder stream (Section 4.4.1)?
##########
src/proxy/http3/QPACK.cc:
##########
@@ -453,39 +457,94 @@ QPACK::update_max_blocking_streams(uint16_t
max_blocking_streams)
this->_max_blocking_streams = max_blocking_streams;
}
+uint32_t
+QPACK::_max_entries() const
+{
+ return this->_max_table_size / 32;
+}
+
int
-QPACK::_encode_prefix(uint16_t largest_reference, uint16_t base_index,
IOBufferBlock *prefix)
+QPACK::_decode_required_insert_count(uint64_t encoded_insert_count, uint32_t
&required_insert_count) const
{
+ // RFC 9204 Section 4.5.1.1.
+ if (encoded_insert_count == 0) {
+ required_insert_count = 0;
+ return 0;
+ }
+
+ uint64_t const full_range = 2 * static_cast<uint64_t>(this->_max_entries());
+ if (encoded_insert_count > full_range) {
+ return -1;
+ }
+
+ uint64_t const max_value = this->_dynamic_table.insert_count() +
static_cast<uint64_t>(this->_max_entries());
+ uint64_t const max_wrapped = (max_value / full_range) * full_range;
+ uint64_t count = max_wrapped + encoded_insert_count - 1;
+
+ if (count > max_value) {
+ if (count <= full_range) {
+ return -1;
+ }
+ count -= full_range;
Review Comment:
No test covers the wrap-around: with this line removed, all of `test_qpack`
still passes.
Could you add a case where the encoded Required Insert Count has wrapped,
i.e. more inserts than `2 * MaxEntries` before the block arrives?
##########
src/proxy/http3/QPACK.cc:
##########
@@ -1336,26 +1424,40 @@ QPACK::_on_encoder_stream_read_ready(IOBufferReader
&reader)
}
QPACKDebug("Received Insert Without Name Ref: name=%.*s, value=%.*s",
static_cast<int>(name_len), name,
static_cast<int>(value_len), value);
- this->_dynamic_table.insert_entry(name, name_len, value, value_len);
+ XpackLookupResult inserted = this->_dynamic_table.insert_entry(name,
name_len, value, value_len);
// Free in reverse allocation order so Arena can rewind both entries.
this->_arena.str_free(value);
this->_arena.str_free(name);
+ if (inserted.match_type == XpackLookupResult::MatchType::NONE) {
+ this->_abort_decode();
+ return EVENT_DONE;
+ }
} else if (buf & 0x20) { // Dynamic Table Size Update
uint16_t max_size;
if (this->_read_dynamic_table_size_update(reader, max_size) < 0) {
this->_abort_decode();
return EVENT_DONE;
}
QPACKDebug("Received Dynamic Table Size Update: max_size=%d", max_size);
- this->_dynamic_table.update_maximum_size(max_size);
+ // RFC 9204 Section 4.3.1 bounds the capacity by the maximum this
decoder advertised.
+ if (max_size > this->_max_table_size ||
!this->_dynamic_table.update_maximum_size(max_size)) {
+ this->_abort_decode();
+ return EVENT_DONE;
+ }
} else { // Duplicates
uint16_t index;
if (this->_read_duplicate(reader, index) < 0) {
this->_abort_decode();
return EVENT_DONE;
}
QPACKDebug("Received Duplicate: index=%d", index);
- this->_dynamic_table.duplicate_entry(index);
+ // The index is relative to the Insert Count (RFC 9204 Section 4.3.4),
and has to name an entry still in the table.
+ if (index >= this->_dynamic_table.count() ||
+
this->_dynamic_table.duplicate_entry(this->_dynamic_table.largest_index() -
index).match_type ==
Review Comment:
Passing `index` straight to `duplicate_entry()`, as an absolute index, still
passes every test. Relative index 0 and the newest entry name the same thing,
so a test that only duplicates the newest entry can't tell the two apart.
Could you add a Duplicate of an older entry and check that the copy has that
entry's name and value (Section 4.3.4)?
##########
src/proxy/http3/QPACK.cc:
##########
@@ -1046,43 +1116,48 @@
QPACK::_decode_literal_header_field_with_postbase_name_ref(int16_t base_index, c
this->_attach_header(hdr, name, name_len, value, value_len, never_index);
header_len = name_len + value_len;
- QPACKDebug("Decoded Literal Header Field With Postbase Name Ref:
base_index=%d, abs_index=%d, name=%.*s, value=%.*s", base_index,
- static_cast<uint16_t>(index), static_cast<int>(name_len), name,
static_cast<int>(value_len), value);
+ QPACKDebug("Decoded Literal Header Field With Postbase Name Ref: base=%u,
abs_index=%u, name=%.*s, value=%.*s", base,
+ absolute_index, static_cast<int>(name_len), name,
static_cast<int>(value_len), value);
this->_arena.str_free(value);
return read_len;
}
int
-QPACK::_decode_header(const uint8_t *header_block, size_t header_block_len,
HTTPHdr &hdr)
+QPACK::_decode_header(uint32_t required_insert_count, const uint8_t
*header_block, size_t header_block_len, HTTPHdr &hdr)
{
const uint8_t *pos = header_block;
size_t remain_len = header_block_len;
int64_t ret;
- // Decode Header Data Prefix
- uint64_t tmp;
- if ((ret = xpack_decode_integer(tmp, pos, pos + remain_len, 8)) < 0 || tmp >
0xFFFF) {
+ // Decode Header Data Prefix. decode() has already reconstructed the
Required Insert Count from the first integer, against
+ // the Insert Count when the block arrived, so it is only skipped here.
+ uint64_t encoded_insert_count;
+ if ((ret = xpack_decode_integer(encoded_insert_count, pos, pos + remain_len,
8)) < 0) {
return -1;
}
- pos += ret;
- remain_len -= ret;
- uint16_t largest_reference = tmp;
+ pos += ret;
+ remain_len -= ret;
- uint64_t delta_base_index;
- uint16_t base_index;
- if ((ret = xpack_decode_integer(delta_base_index, pos, pos + remain_len, 7))
< 0 || delta_base_index > 0xFFFF) {
+ uint64_t delta_base;
+ if (remain_len == 0 || (ret = xpack_decode_integer(delta_base, pos, pos +
remain_len, 7)) < 0) {
return -2;
}
+ // RFC 9204 Section 4.5.1.2.
+ uint64_t base;
if (pos[0] & 0x80) {
- if (delta_base_index == 0) {
+ // Base would be negative.
+ if (required_insert_count <= delta_base) {
Review Comment:
Changing `<=` to `<` here still passes every test, so the Section 4.5.1.2
rule (Sign 1 with Delta Base equal to the Required Insert Count is invalid)
isn't covered.
Could you add a block with Sign 1 and Delta Base equal to its Required
Insert Count, and check that it fails?
##########
src/proxy/http3/QPACK.cc:
##########
@@ -1429,28 +1531,38 @@ QPACK::StaticTable::lookup(const char *name, size_t
name_len, const char *value,
return {candidate_index, match_type};
}
-uint16_t
-QPACK::_calc_absolute_index_from_relative_index(uint16_t base_index, uint16_t
relative_index)
+bool
+QPACK::_calc_absolute_index_from_relative_index(uint32_t base, uint32_t
required_insert_count, uint64_t relative_index,
+ uint32_t &absolute_index)
{
- return base_index - relative_index;
+ if (relative_index >= base) {
+ return false;
+ }
+ absolute_index = base - 1 - static_cast<uint32_t>(relative_index);
+ return absolute_index < required_insert_count;
Review Comment:
Replacing this with `return true` still passes every test, so the Section
2.2.3 bound on relative indices isn't covered.
Could you add a relative reference at or above the Required Insert Count
(Sign 0 with a non-zero Delta Base makes Base larger than it), and check that
the decode fails?
##########
include/proxy/hdrs/XPACK.h:
##########
@@ -233,6 +233,8 @@ class XpackDynamicTable
bool is_empty() const;
uint32_t largest_index() const;
uint32_t count() const;
+ // The number of entries ever inserted, evicted ones included: the Insert
Count of RFC 9204 Section 3.2.4.
+ uint32_t insert_count() const;
Review Comment:
`insert_count()` reads like a function that inserts a count, not a getter.
The neighbouring getters are nouns (`size()`, `maximum_size()`, `count()`,
`largest_index()`), and the value is `_entries_inserted`. Could it be
`entries_inserted()`? The comment can keep the RFC's "Insert Count".
##########
src/proxy/http3/QPACK.cc:
##########
@@ -1429,28 +1531,38 @@ QPACK::StaticTable::lookup(const char *name, size_t
name_len, const char *value,
return {candidate_index, match_type};
}
-uint16_t
-QPACK::_calc_absolute_index_from_relative_index(uint16_t base_index, uint16_t
relative_index)
+bool
+QPACK::_calc_absolute_index_from_relative_index(uint32_t base, uint32_t
required_insert_count, uint64_t relative_index,
+ uint32_t &absolute_index)
{
- return base_index - relative_index;
+ if (relative_index >= base) {
+ return false;
+ }
+ absolute_index = base - 1 - static_cast<uint32_t>(relative_index);
+ return absolute_index < required_insert_count;
}
-uint16_t
-QPACK::_calc_absolute_index_from_postbase_index(uint16_t base_index, uint16_t
postbase_index)
+bool
+QPACK::_calc_absolute_index_from_postbase_index(uint32_t base, uint32_t
required_insert_count, uint64_t postbase_index,
+ uint32_t &absolute_index)
{
- return base_index + postbase_index + 1;
+ if (base >= required_insert_count || postbase_index >= required_insert_count
- base) {
Review Comment:
Disabling this check still passes every test, so the Section 2.2.3 bound on
post-base indices isn't covered.
Could you add a post-base reference at or above the Required Insert Count,
and check that the decode fails?
--
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]