bneradt commented on code in PR #13621:
URL: https://github.com/apache/trafficserver/pull/13621#discussion_r4457590951


##########
src/proxy/http3/QPACK.cc:
##########
@@ -1147,20 +1149,30 @@ QPACK::_on_encoder_stream_read_ready(IOBufferReader 
&reader)
     reader.memcpy(&buf, 1);
     if (buf & 0x80) { // Insert With Name Reference
       bool        is_static;
-      uint16_t    index;
-      const char *name;
-      size_t      name_len;
-      const char *dummy;
-      size_t      dummy_len;
+      uint64_t    index;
+      const char *name      = nullptr;
+      size_t      name_len  = 0;
+      const char *dummy     = nullptr;
+      size_t      dummy_len = 0;
       char       *value;
       size_t      value_len;
       if (this->_read_insert_with_name_ref(reader, is_static, index, 
this->_arena, &value, value_len) < 0) {
         this->_abort_decode();
         return EVENT_DONE;
       }
-      QPACKDebug("Received Insert With Name Ref: is_static=%d, index=%d, 
value=%.*s", is_static, index, static_cast<int>(value_len),
-                 value);
-      StaticTable::lookup(index, &name, &name_len, &dummy, &dummy_len);
+      QPACKDebug("Received Insert With Name Ref: is_static=%d, index=%" PRIu64 
", value=%.*s", is_static, index,
+                 static_cast<int>(value_len), value);
+      XpackLookupResult result;
+      if (is_static) {
+        result = StaticTable::lookup(index, &name, &name_len, &dummy, 
&dummy_len);
+      } else {
+        result = this->_dynamic_table.lookup_relative(index, &name, &name_len, 
&dummy, &dummy_len);
+      }
+      if (result.match_type != XpackLookupResult::MatchType::EXACT) {
+        this->_arena.str_free(value);
+        this->_abort_decode();
+        return EVENT_DONE;
+      }
       this->_dynamic_table.insert_entry(name, name_len, value, value_len);

Review Comment:
   Fixed. On the dynamic branch the referenced name is now copied into `_arena` 
before the insert, and the copy is freed before `value` so the arena can rewind 
both (per #13636):
   
   ```cpp
         if (is_static) {
           this->_dynamic_table.insert_entry(name, name_len, value, value_len);
         } else {
           char *owned_name = this->_arena.str_store(name, name_len);
   
           this->_dynamic_table.insert_entry(owned_name, name_len, value, 
value_len);
           this->_arena.str_free(owned_name);
         }
         this->_arena.str_free(value);
   ```
   
   Static names point into `STATIC_HEADER_FIELDS`, so that branch skips the 
copy.
   
   Added "Insert With Name Reference to an entry the insert evicts", following 
your recipe on a 128-byte table: insert a 62-byte name, then a 91-byte name 
(evicts the first and wraps), then Insert With Name Reference at dynamic 
relative index 0 with an empty value, then decode an Indexed Field Line for the 
newest entry and check that the 91-byte name comes back intact. As you noted, 
it also pins relative vs absolute, since absolute 0 is the evicted entry. With 
the copy reverted, ASan reports the overlap:
   
   ```
   ERROR: AddressSanitizer: memcpy-param-overlap
   SUMMARY: AddressSanitizer: memcpy-param-overlap src/proxy/hdrs/XPACK.cc:609 
in XpackDynamicTableStorage::write(...)
   ```
   
   With the fix in, `test_qpack` and `test_proxy_hdrs_xpack` pass under ASan. 
The branch is also rebased on current master.
   



-- 
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]

Reply via email to